在 databind() 之后保留已检查的项目
我正在填充一个数据表,该数据表又填充一个复选框列表。我希望在添加项目时选择它们。我可以做到这一点,但是当我添加第二个 -> 时第 n 项,它只保留最后一个复选框。有没有办法通过绑定保留选定的复选框?这是我当前的功能:
protected void FinalizeAdd_Click(object sender, EventArgs e)
{
VersionDataTable.AddVersionDataTableRow(Convert.ToInt32(VersionDropDown.SelectedValue), ProductDropDown.SelectedItem.Text + " " + VersionDropDown.SelectedItem.Text);
ProductCheckList.DataSource = VersionDataTable;
ProductCheckList.DataValueField = VersionDataTable.VersionIDColumn.ToString();
ProductCheckList.DataTextField = VersionDataTable.VersionTextColumn.ToString();
ProductCheckList.DataBind();
ProductCheckList.Items[ProductCheckList.Items.Count - 1].Selected = true;
}
提前感谢您的帮助。
I am populating a data table which in turn populates a checkboxlist. I want the items to be selected when they are added. I can do this, however when I add a 2nd -> nth Item, it only keeps the last check box. Is there a way to persist selected check boxes through a bind? here is my current function:
protected void FinalizeAdd_Click(object sender, EventArgs e)
{
VersionDataTable.AddVersionDataTableRow(Convert.ToInt32(VersionDropDown.SelectedValue), ProductDropDown.SelectedItem.Text + " " + VersionDropDown.SelectedItem.Text);
ProductCheckList.DataSource = VersionDataTable;
ProductCheckList.DataValueField = VersionDataTable.VersionIDColumn.ToString();
ProductCheckList.DataTextField = VersionDataTable.VersionTextColumn.ToString();
ProductCheckList.DataBind();
ProductCheckList.Items[ProductCheckList.Items.Count - 1].Selected = true;
}
Thanks for the help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在再次对 CheckboxList 进行数据绑定之前,您必须保存所选项目。
例如(对 VB.NET 很抱歉,但我想你会明白我的意思):
You have to save the selected items before you databind the CheckboxList again.
For example(sorry for VB.NET, but i think you'll understand what i mean):