博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Repeater控件使用
阅读量:7168 次
发布时间:2019-06-29

本文共 4141 字,大约阅读时间需要 13 分钟。

对于Repeater控件,主要是注意HeaderTemplate、ItemTemplate、AlternatingItemTemplate以及FooterTemplate的用法。

1、前台代码
<%@ Page Language="C#" AutoEventWireup="true" Inherits="_Default1" CodeBehind="Default.aspx.cs" %> <%@ Import Namespace="System.Data" %>
    
商品类别列表    
        //-------------------------------------------------------------        // Select all the checkboxes (Hotmail style)        //-------------------------------------------------------------         function SelectAllCheckboxes(spanChk) {            var xState = spanChk.checked;             elm = spanChk.form.elements;            for (i = 0; i < elm.length; i++) {                if (elm[i].type == "checkbox" && elm[i].id != spanChk.id) {                    if (elm[i].checked != xState)                        elm[i].click();                }            }        }        
    
        欢迎您的登录:
    
        
            
                
                    
                        
                                                
                            
序号                                                
                            
类别名称                                                
                            
管理操作                                                        
            
                
                    
                        
<%#((DataRowView)Container.DataItem)["ProductCategory_ID"]%>'                            type="hidden" />                        
                                        
                        <%#Container.ItemIndex + 1%>                                        
                        <%#((DataRowView)Container.DataItem)["ProductCategory_Name"]%>                                        <%--                                
                                    <%#((DataRowView)Container.DataItem)["Student_Age"]%>                                                                
                                    <%# DataBinder.Eval(Container.DataItem, "Student_Birth", "{0:d}")%>                                --%>                    
                        
<%#((DataRowView)Container.DataItem)["ProductCategory_ID"]%>'                            title="查看详情">[查看详情] | 
<%#((DataRowView)Container.DataItem)["ProductCategory_ID"]%>'                                title="修改数据">[修改数据]                                                
            
                
                    
                        
<%#((DataRowView)Container.DataItem)["ProductCategory_ID"]%>'                            type="hidden" />                        
                                        
                        <%#Container.ItemIndex + 1%>                                        
                        <%#((DataRowView)Container.DataItem)["ProductCategory_Name"]%>                                        <%--                                     
                                    <%#((DataRowView)Container.DataItem)["Student_Age"]%>                                                                
                                    <%# DataBinder.Eval(Container.DataItem, "Student_Birth", "{0:d}")%>                                --%>                    
                        
<%#((DataRowView)Container.DataItem)["ProductCategory_ID"]%>'                            title="查看详情">[查看详情] | 
<%#((DataRowView)Container.DataItem)["ProductCategory_ID"]%>'                                title="修改数据">[修改数据]                                                
            
                            
                
           
         
新增
        
                            
                    
                                                            
    2、后台代码
using System;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;using System.Data;using System.Web.UI.HtmlControls;using System.Data.Common;using System.Text; public partial class _Default1 : System.Web.UI.Page{        Ced.BLL.ProductCategory bll = new Ced.BLL.ProductCategory();    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            BindData();        }            }     private void BindData()    {         DataSet ds = new DataSet();        StringBuilder strWhere = new StringBuilder();        ds = bll.GetList(strWhere.ToString());         DataTable dt = ds.Tables[0];        DataView dv = dt.DefaultView;        AspNetPager1.RecordCount = dv.Count;        PagedDataSource pds = new PagedDataSource();        pds.DataSource = dv;        pds.AllowPaging = true;        pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;        pds.PageSize = AspNetPager1.PageSize;        TopList.DataSource = pds;        TopList.DataBind();    }    protected void AspNetPager1_PageChanged(object src, EventArgs e)    {        BindData();    }    protected void DeleteBTN_Click(object sender, EventArgs e)    {        List
 CheckList = GetCheckBoxIDs();        for (int i = 0; i < CheckList.Count; i++)        {            DeleteStudent(CheckList[i].ToString());        }        BindData();    }     private void DeleteStudent(string p)    {        bll.DeleteList(p);    }     #region 得到选种的CheckBox的ID,保存到ArrayList中    public List
 GetCheckBoxIDs()    {        List
 myArrayList = new List
();        CheckBox cb = new CheckBox();        string strID = "";        HtmlInputHidden id;        for (int i = 0; i < this.TopList.Items.Count; i++)        {            cb = (CheckBox)this.TopList.Items[i].FindControl("chkSelect");            id = (HtmlInputHidden)this.TopList.Items[i].FindControl("TopID");            if (cb.Checked == true)            {                strID = id.Value.ToString();//获取值                 myArrayList.Add(strID);            }        }        return myArrayList;    }    #endregion }
 

转载地址:http://yfmwm.baihongyu.com/

你可能感兴趣的文章