Putting a gridview row in edit mode programmatically

前端 未结 5 361
名媛妹妹
名媛妹妹 2020-12-11 01:11

How do I put a gridview row in edit mode programmatically?

相关标签:
5条回答
  • 2020-12-11 01:55

    You may also need to know how to cancel the edit. Just like you set up the "OnRowEditing" command in the gridview, you need to set up the "OnRowCancelingEdit" command. The backend should look similar to this. (VB)

    Sub gridView1_rowCanceling(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs)
        gridView1.EditIndex = -1
        BindData()  // <-- Whatever procedure you use to bind your data to the gridView
    End Sub
    
    0 讨论(0)
  • 2020-12-11 02:00
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        GridView1.EditIndex = 1;
    }
    

    Tested with vs-2008. fork fine.

    0 讨论(0)
  • 2020-12-11 02:10
    protected void gridview_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView gv = (GridView)sender;
        // Change the row state
        gv.Rows[e.NewEditIndex].RowState = DataControlRowState.Edit;           
    }
    
    0 讨论(0)
  • 2020-12-11 02:12

    Set the EditIndex property to the appropriate row and then ReBind the GridVIew again to it's DataSource.

    Hope this helps.

    0 讨论(0)
  • 2020-12-11 02:12

    Just implement the Row_Editing event and do something like this:

    protected void Row_Editing(object sender, GridViewEditArgs e) 
    {
      myGridView.EditItemIndex = e.EditItemIndex; 
      BindData(); 
    }
    

    Bind data will populate the GridView with the data.

    0 讨论(0)
提交回复
热议问题