网格更新事件无效

时间:2013-07-31 10:19:29

标签: asp.net .net gridview

找不到:: RowIndex的错误

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

以下是网格行更新事件....

  protected void GridView1_RowUpdating(object sender, EventArgs e)  
  {         
    GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
    DropDownList ct = (DropDownList)row.FindControl("case_type");
    DropDownList cs = (DropDownList)row.FindControl("case_status");

    con.Open();
    SqlCommand cmd = new SqlCommand("UPDATE intakesheet SET case_number = @case_number, case_name=@case_name, Case_Type=@case_type, Case_Status = @case_status, assigned_date = @assigned_date, assigned_to = @assigned_to, date_withdrawn= @date_withdrawn, date_delivered= @date_delivered, qc_by = @qc_by,  qc_date=@qc_date, additional_notes = @additional_notes WHERE (case_number = @case_number)", con);
    cmd.ExecuteNonQuery();
    GridView1.EditIndex = -1;
    con.Close();
    bind();

}

public void bind()
{

    con.Open();
    SqlDataAdapter da = new SqlDataAdapter("select * from intakesheet", con);
    DataSet ds = new DataSet();
    da.Fill(ds, "intakesheet");
    GridView1.DataSource = ds.Tables[0].DefaultView;
    GridView1.DataBind();
    con.Close();

}

1 个答案:

答案 0 :(得分:3)

更改此行

 protected void GridView1_RowUpdating(object sender, EventArgs e)

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)