演示asp.net中使用Repeater嵌套相关代码

发布时间:2020-06-21 05:58:05 作者:yzuisoz
来源:网络 阅读:560

前台:
   
    <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">

    <ItemTemplate>
   
    <ul>
   
    <li>
   
    <%#Eval("DepId")%>
   
    <%#Eval("Name")%></li></ul>
   
    <asp:Repeater ID="Repeater2" runat="server">
   
    <ItemTemplate>
   
    <asp:CheckBox ID="cb" runat="server" Text='<%#Eval("RealName")%>' />
   
    <asp:HiddenField ID="hidId" Value='<%#Eval("UserId")%>' runat="server" />
   
    </ItemTemplate>
   
    </asp:Repeater>
   
    </ItemTemplate>
   
    </asp:Repeater>
   
    后台:
   
    protected void Page_Load(object sender, EventArgs e)
   
    {
   
    if (!Page.IsPostBack)
   
    {
   
    CF.Model.Department modelDepartment = new CF.Model.Department();
   
    CF.BLL.Department bllDepartment = new CF.BLL.Department();
   
    DataSet ds = bllDepartment.GetAllList();
   
    Repeater1.DataSource = ds.Tables[0].DefaultView;
   
    Repeater1.DataBind();
   
    }
   
    }
   
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
   
    {
   
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
   
    {
   
    Repeater rp = (Repeater)e.Item.FindControl("Repeater2");
   
    string id = DataBinder.Eval(e.Item.DataItem, "DepId")。ToString();  //取得部门id
    //根据当前部门的id从人员表中查找员工的数据
   
    CF.Model.Users modelUsers = new CF.Model.Users();
   
    CF.BLL.Users bllUsers = new CF.BLL.Users();
   
    DataSet dsUsers = bllUsers.GetList("DepId=" + id);
   
    rp.DataSource = dsUsers.Tables[0].DefaultView;
   
    rp.DataBind();
   
    }
   
    }
   
    //提交培训名单
   
    protected void btnSubmit_Click(object sender, EventArgs e)
   
    {
   
    string trainPersonsId="";
   
    string trainPersonsNames="";
   
    for (int i = 0; i < this.Repeater1.Items.Count; i++)
   
    {
   
    Repeater rptPersons = (Repeater)this.Repeater1.Items[i].FindControl("Repeater2");
   
    for (int j = 0; j < rptPersons.Items.Count; j++)
   
    {
   
    int id = Convert.ToInt32(((HiddenField)rptPersons.Items[j].FindControl("hidId"))。Value);
   
    CheckBox cb = (CheckBox)rptPersons.Items[j].FindControl("cb");
   
    if (cb.Checked)
   
    {
   
    trainPersonsId += id + ",";
   
    trainPersonsNames += cb.Text.Trim() + ",";
   
    }
   
    }
   
    //foreach (RepeaterItem item in rptPersons.Items)
   
    //{
   
    //    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
   
    //    {
   
    //        CheckBox cb = item.FindControl("cb") as CheckBox;
   
    //        if (cb.Checked)
   
    //        {
   
    //            trainPersonsNames += cb.Text + "|";
   
    //        }
   
    //    }
   
    }
   
    if (trainPersonsId != "")
   
    {
   
    //去除最后一个字符 
    
    trainPersonsId = trainPersonsId.Substring(0, trainPersonsId.Length - 1);
   
    }
   
    if (trainPersonsNames != "")
   
    {
   
    //去除最后一个字符
   
    trainPersonsNames = trainPersonsNames.Remove(trainPersonsNames.Length - 1);
   
    }
   
    Response.Redirect("add.aspx?trainPersonsId=" + trainPersonsId + "&&trainPersonsNames=" + trainPersonsNames);
   
    //JscriptMsg("提交成功啦!", "add.aspx?trainPersonsId=" + trainPersonsId + "&&trainPersonsNames=" + trainPersonsNames, "Success");
   
    //JscriptMsg("审核通过成功啦!", Utils.CombUrlTxt("list.aspx", "channel_id={0}&keywords={1}&property={2}",
   
    //    this.channel_id.ToString(), this.keywords, this.property), "Success");
   
    }
 

推荐阅读:
  1. Repeater的嵌套结合用户控件的使用
  2. Repeater中嵌套使用Repeater的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

server asp.net

上一篇:python:xml模块用法-xml处理、修改、删除

下一篇:Kafka 监控架构设计

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》