如何编辑GridView

时间:2016-01-10 11:04:52

标签: c# asp.net gridview

我想编辑GridView而不涉及数据库

protected void myGridView_RowUpdating(object sender,GridViewUpdateEventArgs e)
{
    string reg = (myGridView.DataKeys[e.RowIndex].Value.ToString());
    GridViewRow row = (GridViewRow)myGridView.Rows[e.RowIndex];
    TextBox name = (TextBox)row.Cells[1].Controls[0];
    TextBox email = (TextBox)row.Cells[2].Controls[0];

    myGridView.EditIndex = -1;
    BindGird();
}

这是我的bindgrid功能:

protected void BindGird() 
{
    DataTable dt = (DataTable)Session["myCart"]; 
    this.myGridView.DataSource = dt; this.myGridView.DataBind(); 
} 

这是行编辑事件

protected void myGridView_RowEditing(object sender, GridViewEditEventArgs e) 
{ 
    myGridView.EditIndex = e.NewEditIndex; BindGird(); 
} 

0 个答案:

没有答案