C# Asp.net使用AutoGenerateEditButton更新GridView

C# Asp.net使用AutoGenerateEditButton更新GridView,c#,asp.net,datagrid,insert,C#,Asp.net,Datagrid,Insert,如何使用AutoGenerateEditButton更新我的gridview表(已绑定数据集-从sql数据库检索数据集) --删除问题中的断开代码以在答案中放入固定代码--要获取更新行的值,请将其添加到“行更新”事件处理程序中 protected void grdViewDetails_RowEditing1(object sender, GridViewEditEventArgs e) { grdViewDetails.EditIndex = e.N

如何使用AutoGenerateEditButton更新我的gridview表(已绑定数据集-从sql数据库检索数据集)


--删除问题中的断开代码以在答案中放入固定代码--

要获取更新行的值,请将其添加到“行更新”事件处理程序中

 protected void grdViewDetails_RowEditing1(object sender, GridViewEditEventArgs e)
        {
            grdViewDetails.EditIndex = e.NewEditIndex;
            //e.newedit index:- will be provide index of row for which edit button is selected
            grdViewDetails.DataSource = yourdatasource //mine was a datset
            grdViewDetails.DataBind();
        }
受保护的void grdViewDetails\u行更新(对象发送方,GridViewUpdateEventArgs e) {

        GridViewRow row = (GridViewRow)grdViewDetails.Rows[e.RowIndex];

        foreach (Control item in row.Controls)
        {
            if (item.Controls[0] is TextBox)
            {
                TextBox textbox = (TextBox)item.Controls[0];
                string x = textbox.Text; //theres your value you can do stuff with
            }
            if (item.Controls[0] is Label)
            {
                Label mylabel = (Label)item;
                //do stuff - just do the same as the textbox
            }
        }
}

和在“行编辑”事件处理程序中

 protected void grdViewDetails_RowEditing1(object sender, GridViewEditEventArgs e)
        {
            grdViewDetails.EditIndex = e.NewEditIndex;
            //e.newedit index:- will be provide index of row for which edit button is selected
            grdViewDetails.DataSource = yourdatasource //mine was a datset
            grdViewDetails.DataBind();
        }