您的位置:首页 > 产品设计 > UI/UE

为什么CheckBoxList 绑定数据后 要在读取不到Text 和Value ?

2010-06-18 04:07 399 查看
绑定数据:

...
CheckBoxList.DataSource = dt;
CheckBoxList.DataTextField = "text"; CheckBoxList.DataValueField = "id";
CheckBoxList.DataBind();


读取Value:

for (int i = 0; i < ChenkBoxList.Items.Count; i++)
{
if (ChenkBoxList.Items[i].Selected == true)
{
Label1.Text += ChenkBoxList.Items[i].Value + "|";
}
}


注意:在绑定页面的protected void Page_Load(object sender, EventArgs e)要加上海if (!IsPostBack) 如:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
...
CheckBoxlist.DataSource = dt;
CheckBoxlist.DataTextField = "Text";
CheckBoxlist.DataValueField = "id";
CheckBoxlist.DataBind();

...
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: