0

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

在此处输入图像描述

--删除了问题中的Broken代码,将Fixed代码放入Answer--

4

1 回答 1

1

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

protected void grdViewDetails_RowUpdating(对象发送者,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
            }
        }

}

并在“RowEditing”事件处理程序中

 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();
        }
于 2013-04-16T08:08:05.447 回答