我想绑定(bind)与 CheckBoxlist 中的 DataTable 不同的文本和不同的值
在我的 DataTable 中有两列
UserName UserID
AAAAA 12
BBBBB 13
我在复选框列表中绑定(bind)了这个数据表
this.CheckList.DataSource = dataTable;
this.CheckList.DataBind();
问题是什么?在将文本绑定(bind)为 UserName 并将值也绑定(bind)为 Username 之后
但这里我想将值绑定(bind)为 UserID。
有什么想法吗?提前致谢
请您参考如下方法:
您必须设置 DataValueField和 DataTextField属性:
this.CheckList.DataSource = dataTable;
this.CheckList.DataValueField = "UserID";
this.CheckList.DataTextField = "UserName";
this.CheckList.DataBind();
