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

时间:2013-08-28 11:52:22

标签: c# asp.net gridview arraylist dataset

我是.net开发的新手

我想在DataSet中添加gridview值

在下面的代码而不是使用ArrayList我想使用数据集

代码:

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;
}

此处如何在数据集中添加“chkCol0”

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

有什么想法吗?提前致谢

1 个答案:

答案 0 :(得分:0)

        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);