网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

使用asp.net怎么在Repeater中使用复选框-创新互联

这篇文章将为大家详细讲解有关使用asp.net怎么在Repeater中使用复选框,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

创新互联公司:从2013年创立为各行业开拓出企业自己的“网站建设”服务,为上千余家公司企业提供了专业的成都做网站、成都网站建设、网页设计和网站推广服务, 按需定制由设计师亲自精心设计,设计的效果完全按照客户的要求,并适当的提出合理的建议,拥有的视觉效果,策划师分析客户的同行竞争对手,根据客户的实际情况给出合理的网站构架,制作客户同行业具有领先地位的。

.aspx文件中:

<%--顶层Repeater--%>
        
            
             <%# Eval("ChannelName")%>
             <%--嵌套的Repeater,指定使用后台创建的Releation来获取数据源--%>
              ' runat="server">
                
                  ' runat="server" />
                  '>
                
              
             <%--end 嵌套的Repeater,指定使用后台创建的Releation来获取数据源--%>
            
        
        <%--end 顶层Repeater--%>

.aspx.cs文件中:

#region Repeater嵌套的Repeater中使用复选框
      //★Repeater嵌套-经典运用★
      string sqlstr1, sqlstr2;
      sqlstr1 = "select distinct a.ChannelID,b.ChannelName from IE_FlagGroup a left join IE_Channel b on a.ChannelID=b.ChannelID where a.isClose=0 order by a.ChannelID asc";
      sqlstr2 = "select * from IE_FlagGroup where isClose=0 order by FlagID asc";
      DataSet dsChannel = DBFun.dataSetTwo(sqlstr1, "Channel", sqlstr2, "Classify", "myrelation");
      dsChannel.Relations.Add("myrelation", dsChannel.Tables["Channel"].Columns["ChannelID"], dsChannel.Tables["Classify"].Columns["ChannelID"], false);
      this.rptChannel.DataSource = dsChannel.Tables["Channel"];//绑定顶层Repeater(注意:只要绑定顶层就好,嵌套层不能绑定)
      this.rptChannel.DataBind();
      #endregion

//……略相关数据库操作代码

#region 设置Repeater嵌套的Repeater中相应的复选框为选中状态
          string[] selTeamflag = drw["Teamflag"].ToString().Split(',');
          HtmlInputCheckBox checkBox;
          Repeater rpClass;

          for (int i = 0; i < this.rptChannel.Items.Count; i++)
          {
            rpClass = (Repeater)this.rptChannel.Items[i].FindControl("rptClassify");
            for (int j = 0; j < rpClass.Items.Count; j++)
            {
              checkBox = (HtmlInputCheckBox)rpClass.Items[j].FindControl("chk_FlagID");
              if (selTeamflag.Contains(checkBox.Value))
                checkBox.Checked = true;
            }
          }
          #endregion

#region 获取Repeater嵌套的Repeater中的复选框所选择的值的组合,以","隔开
    string str_Teamflag = "";
    HtmlInputCheckBox checkBox;
    Repeater rpClass;

    for (int i = 0; i < this.rptChannel.Items.Count; i++)
    {
      rpClass = (Repeater)this.rptChannel.Items[i].FindControl("rptClassify");
      for (int j = 0; j < rpClass.Items.Count; j++)
      {
        checkBox = (HtmlInputCheckBox)rpClass.Items[j].FindControl("chk_FlagID");
        if (checkBox.Checked)
          str_Teamflag += checkBox.Value + ",";
      }
    }

    if (str_Teamflag != "")
    {
      //去除最后一个字符
      //str_Teamflag = str_Teamflag.Substring(0, str_Teamflag.Length - 1);
      str_Teamflag = str_Teamflag.Remove(str_Teamflag.Length - 1);
    }
    #endregion

关于使用asp.net怎么在Repeater中使用复选框就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


新闻名称:使用asp.net怎么在Repeater中使用复选框-创新互联
网页路径:http://bjjierui.cn/article/ijeio.html

其他资讯