如何从asp.net中动态创建的checkboxlist中获取选定的值

时间:2018-01-15 11:27:59

标签: c# asp.net

我无法从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>

0 个答案:

没有答案