Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果标题未数据绑定,单击编辑按钮时如何获取GridView行中的文本框?_C#_Asp.net - Fatal编程技术网

C# 如果标题未数据绑定,单击编辑按钮时如何获取GridView行中的文本框?

C# 如果标题未数据绑定,单击编辑按钮时如何获取GridView行中的文本框?,c#,asp.net,C#,Asp.net,我有一个GridView,而GridView的标题字段是我程序中列表框中的项目。因此,每次运行时生成的列数都是动态的。基于此,如果单击我的GridView中关联的编辑按钮,如何为该行的每个单元格生成文本框 我编写的.cs代码是: protected void DONE4_Click(object sender, EventArgs e) { Panel7.Visible = true; SqlDataAdapter mydat = new SqlDataAdapter("SEL

我有一个
GridView
,而
GridView
的标题字段是我程序中
列表框中的项目。因此,每次运行时生成的列数都是动态的。基于此,如果单击我的
GridView
中关联的编辑按钮,如何为该行的每个单元格生成
文本框

我编写的.cs代码是:

protected void DONE4_Click(object sender, EventArgs e)
{
    Panel7.Visible = true;

    SqlDataAdapter mydat = new SqlDataAdapter("SELECT DISTINCT Profile_Instance FROM Profile_Master", con);
    DataSet dst = new DataSet();
    mydat.Fill(dst, "Table");
    ListBox3.Items.Clear();
    ListBox3.DataSource = dst.Tables[0];
    ListBox3.DataTextField = dst.Tables[0].Columns["Profile_Instance"].ColumnName;
    ListBox3.DataBind();

    int count = ListBox3.Items.Count;

    DataTable dt = new DataTable();
    DataRow rw = default(DataRow);
    for (int i = 0; i < ListBox1.Items.Count; i++)
    {
        dt.Columns.Add(ListBox1.Items[i].ToString(),
                                       System.Type.GetType("System.String"));
    }

    for (int j = 0; j < count; j++)
    {
        rw = dt.NewRow();
        for (int i = 0; i < ListBox1.Items.Count; i++)
        {
            rw[ListBox1.Items[i].ToString()] = " ";
        }
        dt.Rows.Add(rw);
    }

    GridView2.DataSource = dt;
    GridView2.DataBind();

    foreach (GridViewRow grdRow in GridView2.Rows)
    {
        DropDownList bind_dropdownlist = new DropDownList();                                                    // defining the property of the DropDownList as bind_dropdownlist
        bind_dropdownlist = (DropDownList)(GridView2.Rows[grdRow.RowIndex].Cells[0].FindControl("Pro_List"));   // finding the  DropDownList from the gridiew for binding
        SqlDataAdapter mydata = new SqlDataAdapter("SELECT DISTINCT Profile_Instance FROM Profile_Master", con);
        DataSet dset = new DataSet();                                                                           // binding the DropDownList with the dataset ds
        mydata.Fill(dset, "Table");
        bind_dropdownlist.DataSource = dset;
        bind_dropdownlist.DataTextField = "Profile_Instance";                                                   // set the DropDownList's DataTextField as designation which display the designation in the dropdownlist after fetching the data from database
        bind_dropdownlist.DataBind();
        bind_dropdownlist.Items.Insert(0, new ListItem("---Choose Profile---", "-1"));
    }
}

有人能帮我吗?我希望问题是清楚的。

如果您没有绑定
GridView
并且仍然希望访问其中的控件,那么可以使用
GridViewRow
属性

protected void grd_RowEditing(object sender, GridViewEditEventArgs e) 
{
     GridViewRow selectRow = grd.Rows[e.NewEditIndex];
     TextBox txtKj=(TextBox)selectRow.Cells[3].FindControl("txtKjId"); 
}

这给了我一个错误:非invocable成员'System.Web.UI.WebControl.GridView.Rows'不能像方法一样使用。