zoukankan      html  css  js  c++  java
  • Repeater的嵌套和内部排序

    Repeater的嵌套在外层Repeater添加事件onitemdatabound,在cs页面写内部Repeater的方法。

    Repeater的内部排序在aspx页面增加lable控件,在所在的repeat控件增加OnItemDataBound事件,在cs页面事件里写lable方法。

    .aspx页面

     <asp:Repeater ID="repcompanysheng" runat="server" onitemdatabound="repcompanysheng_ItemDataBound">
        <ItemTemplate>
                    <div class="row">
                        
                        <div class="col-md-8 col-sm-12 col-xs-12" style=" 100%">
    
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                  第
                                  <%#Eval("Stype")%>
                                  次结果公布
                                </div> 
                                <div class="panel-body">
                                    <div class="table-responsive">
                                        <table class="table table-striped table-bordered table-hover">
                                            <thead>
                                                <tr>
                                                    <th>名次</th>
                                                    <th>部门</th>
                                                    <th>参与人数</th>
                                                    <th>总分数</th>
                                                 
                                                </tr>
                                            </thead>
                                            <tbody>
    
                                               
                                                        <asp:Repeater ID="repUser" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
                                                  <ItemTemplate>
                                                <tr>
                                                    <td><%--<%# this.repUser.Items.Count + 1%>--%>
                                                    <%--<%# Container.ItemIndex + 1 %>--%>
                                                     <asp:Label ID="no" runat="server" Text=""></asp:Label>
                                                    </td>
                                                    <td><%#Eval("Name")%> </td>
                                                    <td><%#Eval("renshu")%> 人</td>
                                                    <td><%#Eval("zongfen")%> 分 </td>
                                                  
                                                </tr>
                                                    </ItemTemplate>
                                                       </asp:Repeater>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
    
                        </div>
                    </div>
                    </ItemTemplate>
                    </asp:Repeater>
    

      .cs页面

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    getUser();
                }
            }
    
            public void getUser()
            {
    
                //string sqlUser = "select DID,Name,sum(score) as zongfen,count(distinct UserID)as renshu  from content_info,Department_info where content_info.DID=Department_info.ID group by DID,Name  order by zongfen desc";
                //BaseClass.BindRpt(repUser, sqlUser);
    
                string sqlUser = "select distinct Stype from content_info";
                BaseClass.BindRpt(repcompanysheng, sqlUser);
    
            }
    
            protected void repcompanysheng_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                //判断里层repeater处于外层repeater的哪个位置( AlternatingItemTemplate,FooterTemplate,
    
                //HeaderTemplate,,ItemTemplate,SeparatorTemplate)
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    Repeater rep = e.Item.FindControl("repUser") as Repeater;//找到里层的repeater对象
                    DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 
    
    
                    string strCompanyn = Convert.ToString(rowv["Stype"]);
    
                    DataAccess.Da dac = new DataAccess.Da();
                    string sql = " select DID,Name,sum(score) as zongfen,count(distinct UserID)as renshu  from content_info,Department_info where content_info.DID=Department_info.ID and content_info.Stype='" + strCompanyn + "' group by DID,Name  order by zongfen desc";
    
                    SqlConnection conn = BaseClass.DBCon();
                    SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
                    DataSet ds = new DataSet();
                    sda.Fill(ds);
                    rep.DataSource = ds.Tables[0].DefaultView;
                    rep.DataBind();
    
                   
    
    
    
                }
            }
    
            protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Label lb_no = (Label)e.Item.FindControl("no");
                lb_no.Text = (1 + e.Item.ItemIndex).ToString();
            }
            }
    

      

  • 相关阅读:
    5.2基础标签学习
    6.15ajax选房子
    6.15ajax写数据库的增删改查
    [Ext JS 4] 实战之Grid, Tree Gird 添加按钮列
    DOM4J 读取XML配置文件进行数据库连接
    Bit Map解析
    图像像素操作
    九度OJ 1025 最大报销额(01背包)
    MYSQL :逗号分隔串表,分解成竖表
    interrupt & storage & DMA
  • 原文地址:https://www.cnblogs.com/huichao1314/p/10656185.html
Copyright © 2011-2022 走看看