简体   繁体   English

如何在数据集中添加gridview子控件的值?

[英]How to add gridview child controls values in dataset?

I'm new to .net development 我是.net开发的新手

I want to add gridview values in DataSet 我想在DataSet中添加gridview值

In the below code instead of using ArrayList I want to use Dataset 在下面的代码中,我想使用数据集而不是使用ArrayList

Code: 码:

private void GetCheckBoxStates()
{
    CheckBox chkCol0 = (CheckBox)EmpMasterGrid.HeaderRow.Cells[0]
                            .FindControl("chkCol0");
    CheckBox chkCol1 = (CheckBox)EmpMasterGrid.HeaderRow.Cells[0]
                            .FindControl("chkCol1");
    CheckBox chkCol2 = (CheckBox)EmpMasterGrid.HeaderRow.Cells[0]
                            .FindControl("chkCol2");
    CheckBox chkCol3 = (CheckBox)EmpMasterGrid.HeaderRow.Cells[0]
                            .FindControl("chkCol3");
    CheckBox chkCol4 = (CheckBox)EmpMasterGrid.HeaderRow.Cells[0]
                            .FindControl("chkCol4");
    CheckBox chkCol5 = (CheckBox)EmpMasterGrid.HeaderRow.Cells[0]
                            .FindControl("chkCol5");
    CheckBox chkCol6 = (CheckBox)EmpMasterGrid.HeaderRow.Cells[0]
                            .FindControl("chkCol6");
    ArrayList arr;

    if (ViewState["ds"] == null)
    {
        arr = new ArrayList();
    }
    else
    {
        arr = (ArrayList)ViewState["ds"];
    }
    arr.Add(chkCol0.Checked);
    arr.Add(chkCol1.Checked);
    arr.Add(chkCol2.Checked);
    arr.Add(chkCol3.Checked);
    arr.Add(chkCol4.Checked);
    arr.Add(chkCol5.Checked);
    arr.Add(chkCol6.Checked);
    ViewState["ds"] = arr;
}

Here How to add "chkCol0" in dataset 此处如何在数据集中添加“ chkCol0”

if (ViewState["ds"] == null)
{
  DataSet  arr = new DataSet  ();
}
else
{
    arr = (DataSet)ViewState["ds"];
}
arr.Add("Here how to add chkCol0");

Any ideas? 有任何想法吗? Thanks in advance 提前致谢

        DataTable dt = new DataTable();
        dt.Columns.Add("checkbox");
        dt.Rows.Add("chkCol0",1);
        dt.Rows.Add("chkCol1", 1);
        dt.Rows.Add("chkCol2", 1);
        dt.Rows.Add("chkCol3", 1);
        dt.Rows.Add("chkCol4", 1);
        dt.Rows.Add("chkCol5", 1);
        dt.Rows.Add("chkCol6", 1);
        DataSet ds = new DataSet();
        ds.Tables.Add(dt);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM