【问题标题】:Asp.net Update GridView with AutoGenerateEditButtonAsp.net 使用 AutoGenerateEditButton 更新 GridView
【发布时间】:2013-04-12 15:16:56
【问题描述】:

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

--删除问题中的Broken code,将Fixed code放入Answer--

【问题讨论】:

    标签: c# asp.net datagrid insert


    【解决方案1】:

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

    protected void grdViewDetails_RowUpdating(object sender, 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();
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多