• 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();
            }
            }
    

      

  • 相关阅读:
    leetcode_09_Palindrome Number (easy)
    JQuery与JavaScript与Ajax三者的区别与联系
    Blockly常用函数
    JavaWeb中四大域对象
    Thymeleaf知识
    列表、字典、元组、集合的区别
    Spring Boot拦截器
    AWS路由表
    Android调试工具DDMS的使用详解
    Android 列表单选对话框
  • 原文地址:https://www.cnblogs.com/huichao1314/p/10656185.html
Copyright © 2020-2023  润新知