我无法从CheckBoxList中获取我正在动态创建的选定值。点击按钮,我试图获取所选的复选框值,但我不知道这可以完成。以下是我尝试过的代码。
Class.cs
private void PopulateCheckBoxes()
{
LeaveController contLeave = new LeaveController();
Models.Leave l = new Models.Leave();
l.lr = contLeave.GetAllReasons(); //Getting values from database into list
ListItem listc = new ListItem();
foreach (var item in l.lr)
{
listc.Value = item.Id;
listc.Text = item.Title;
listc.Selected = item.ischecked;
lst.Items.Add(new ListItem(listc.Text, listc.Value, listc.Selected));
}
chkboxpanel.Controls.Add(lst);
}
protected void btn_save_Click(object sender, EventArgs e)
{
//Here i want to get the value of the selected checkbox from the list
}
View.aspx
<asp:Panel ID="chkboxpanel" name="ChkPanel" runat="server">
.....
</asp:Panel>