我也想在不再次调用绑定方法的情况下保留datatable
inCheckListBox
attributes
方法的值postback
所以我有一个asp:CheckBoxList
并且我正在绑定它
if (!IsPostBack)
{
// code for binding
}
ASP.NET
<asp:CheckBoxList ID="chkboxCandidateList" runat="server">
</asp:CheckBoxList>
这是我的绑定方法C#
DataTable dtCandidateName = // datatable having all specified column
if (dtCandidateName != null && dtCandidateName.Rows.Count > 0)
{
chkLstBxCandidateName.Items.Clear();
ListItem lstItem = null;
for (int i = 0; dtCandidateName.Rows.Count > i; i++)
{
lstItem = new ListItem(Convert.ToString(dtCandidateName.Rows[i]["Candidate Name"]), Convert.ToString(dtCandidateName.Rows[i]["Candidate Id"]));
lstItem.Attributes.Add("Email", Convert.ToString(dtCandidateName.Rows[i]["Email"]));
lstItem.Attributes.Add("Mobile", Convert.ToString(dtCandidateName.Rows[i]["Mobile"]));
chkLstBxCandidateName.Items.Add(lstItem);
}
}
甚至我在第一次调用页面加载时也得到了值
HTML
<span email="test@kartika.com" mobile="01111111111"><input id="ContentPlaceHolder1_chkboxCandidateList_0" type="checkbox" name="ctl00$ContentPlaceHolder1$chkboxCandidateList$0" checked="checked" value="486"><label for="ContentPlaceHolder1_chkboxCandidateList_0">Kratika Shukla</label></span>
因此,当我单击提交按钮时,我没有获得电子邮件和移动设备的价值
chkboxCandidateList.Items[i].Attributes["Email"] -- getting null
我检查了这篇文章,但对答案不满意