动态生成多个选择项【c#】

2021/9/6 14:07:20

本文主要是介绍动态生成多个选择项【c#】,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

  <asp:CheckBoxList ID="cbxLabelList" runat="server" RepeatColumns="10" RepeatDirection="Horizontal">
            </asp:CheckBoxList>
			
			
			   DataTable dtinfo = pc.getdatainfo("");
           
            cbxLabelList.Items.Clear();
            if (dtinfo.Rows.Count>0)
                for (int t = 0; t < dtinfo.Rows.Count; t++) {
                    string name = Convert.ToString(dtinfo.Rows[t][1]);
                    cbxLabelList.Items.Add(name);
                }
            List<string> list = new List<string>();
            for (int i = 0; i < cbxLabelList.Items.Count; i++)
            {
                if (cbxLabelList.Items[i].Selected)
                    list.Add(cbxLabelList.Items[i].Text);
            }
			
			
			foreach (ListItem cb in cbxLabelList.Items)
                {
                    if (cb.Selected == true)
                    {
                       cb.Value //每个值
					   pc.adddateinfo(cb.Value);
                     
                    }
                }
				
				
//赋值/回显:
string info = Convert.ToString(dtDate.Rows[0]["Infos"]);
            
                string[] arr=   info.Split(',');
                for (int c=0;c<arr.Length-1;c++) {
                        infolist.Items.Add(arr[c]);
                }
                foreach (string ar in arr)
                {
                    foreach (ListItem it in infolist.Items)
                    {
                        if (ar == it.Value)
                            it.Selected = true;
                        else
                            continue;
                    }
                }				

  



这篇关于动态生成多个选择项【c#】的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程