- PHP basename() 函数
- ASP.NET中常用的26个优化性能方法
- 使用css、li、ul、div及js制作二级树形下拉菜单
- access三表连接 实用
- 小程序中的小数计算问题
- axios安装与使用
- 在设计视图中Access允许的九种数据类型
- seo学习之入门宝典
- 网站二级域名用.net 2.0实现方案
- 基于对象的JavaScript语言
邮箱:
手机:15383239821
checkboxlist绑定数据方法
1、把数据绑定到CheckBoxList中
特别要注意加载顺序
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection con = GetDBCon.GetCon();
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from admin", con);
DataSet ds = new DataSet();
sda.Fill(ds,"admin");
this.CheckBoxList1.DataSource = ds.Tables[0];
this.CheckBoxList1.DataTextField = "username";//绑定的字段名
this.CheckBoxList1.DataValueField = "userid";//绑定的值
this.CheckBoxList1.DataBind();
}
}
2、循环读取出来
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.Lab2.Text = "";
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (this.CheckBoxList1.Items[i].Selected)
{
this.Lab2.Text = this.Lab2.Text+CheckBoxList1.Items[i].Text+".";
}
}
}
3、CheckBoxList取值
string strrighgs = "";
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected == true)
{
strrighgs += CheckBoxList1.Items[i].Value+"|";
}
}
string str = "";
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected == true)
{
str += li.Value+";";
}
}
Response.Write(str);
Response.End();
CheckBoxList取值及勾选
string[] strtemp = strapp.Split('|');
foreach (string str in strtemp)
{
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Value == str)
{
CheckBoxList1.Items[i].Selected = true;
}
}
}
- 上一篇:c#窗体 textbox 限制输入的字符只能为时间格式
- 下一篇:DTO介绍
-
2025-02-04deepseek-r1的1.5b、7b、8b、14b、32b、70b和671b有啥区别?
-
2013-06-11C# 字符串操作类
-
2025-11-08多语言网站的Hreflang标签优化指南
-
2023-09-17JWT lcobucci/jwt
-
2013-06-10经典SQL语句大全 .
