获取复选框值并存储在 IList 中
本文关键字:IList 存储 复选框 获取 | 更新日期: 2023-09-27 18:30:29
需要一些帮助,因为我仍然是编程新手。我有一个网格视图,它有五列,三列由复选框组成。然后,如果选中了这些复选框并将其放入IList中,我需要获取这些复选框值。我的问题是在将其添加到我的 IList 时如何实现它。请帮忙。请参阅下面的代码。我知道有些不对劲。
public IList<Title> Checkboxes
{
get
{
CheckBox chkEPS;
CheckBox chkIMDF;
CheckBox chkPS;
IList<Title> checkedList = new List<Title>();
foreach (GridViewRow row in gvwTitles.Rows)
{
chkABC = (CheckBox)row.FindControl("chkABC");
chkABCD = (CheckBox)row.FindControl("chkABCD");
chkABCDE = (CheckBox)row.FindControl("chkABCDE");
if ((chkABC.Checked) && (chkABCD.Checked) && (chkABCDE.Checked))
{
checkedList.Add(new Title(What will be the value));
// how will I add the value, I am also considering what if the user check the chkABC checkbox, while the others were not checked??
}
}
return checkedList;
}
}
public Title(int id, bool _isPocketSharing, bool _isPreventSplitting, bool _isMissingDataFile)
我假设您想在复选框或选中与否的基础上添加标题 prperty
您可以使用三元运算符来使用此? :
我认为你需要这个
public IList<Title> Checkboxes
{
get
{
CheckBox chkEPS;
CheckBox chkIMDF;
CheckBox chkPS;
IList<Title> checkedList = new List<Title>();
foreach (GridViewRow row in gvwTitles.Rows)
{
chkABC = (CheckBox)row.FindControl("chkABC");
chkABCD = (CheckBox)row.FindControl("chkABCD");
chkABCDE = (CheckBox)row.FindControl("chkABCDE");
checkedList.Add(new Title(1 , chkABC.Checked ? true : false, chkABCD.Checked ? true : false, chkABCDE.Checked ? true : false));
}
return checkedList;
}
}
试试这个:
checkedList.Add(new Title{name=1 ,name2=??,name3= ??, name4=??});//name,name1,name2,name..is suppose to your property of class "Title"