0

需要一些帮助,因为我仍然是编程新手。我有一个有五列的gridview,三列由复选框组成。然后,如果它们被选中,我需要获取这些复选框的值并将其放入 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)
4

2 回答 2

1

我假设您想在复选框或选中与否的基础上添加标题属性

您可以为此使用三元运算符? :

我想你需要这个

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;            
    }                  
}
于 2013-09-06T13:14:55.577 回答
0

尝试这个:

  checkedList.Add(new Title{name=1 ,name2=??,name3= ??, name4=??});//name,name1,name2,name..is suppose to your property of class "Title"
于 2013-09-06T13:11:36.297 回答