过滤后编辑和删除gridview不起作用

时间:2016-08-25 19:18:50

标签: asp.net

我有一个gridview,其中编辑和删除工作正常。但是,当我搜索任何记录并尝试编辑该记录时,gridview在过滤之前会以某种方式重置为状态。

这是我的代码:

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
    GridView1.EditIndex = e.NewEditIndex;
    Databind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    string TableID=GridView1.DataKeys[e.RowIndex].Value.ToString();
    string Name = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
    string Dept = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
    string AttendMonth = ((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
    string AttendYear = ((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).Text;
    string Month_H = ((TextBox)GridView1.Rows[e.RowIndex].Cells[7].Controls[0]).Text;
    string Absent_H = ((TextBox)GridView1.Rows[e.RowIndex].Cells[8].Controls[0]).Text;
    string Miss_punch_H = ((TextBox)GridView1.Rows[e.RowIndex].Cells[9].Controls[0]).Text;
    string Late_H = ((TextBox)GridView1.Rows[e.RowIndex].Cells[10].Controls[0]).Text;
    string Eid_H = ((TextBox)GridView1.Rows[e.RowIndex].Cells[11].Controls[0]).Text;
    string train_H = ((TextBox)GridView1.Rows[e.RowIndex].Cells[12].Controls[0]).Text;
    string Manager_H = ((TextBox)GridView1.Rows[e.RowIndex].Cells[13].Controls[0]).Text;
    string Des_H = ((TextBox)GridView1.Rows[e.RowIndex].Cells[14].Controls[0]).Text;
    string Percent = ((TextBox)GridView1.Rows[e.RowIndex].Cells[15].Controls[0]).Text;
    string Notes = ((TextBox)GridView1.Rows[e.RowIndex].Cells[16].Controls[0]).Text;

    if (DA.UpdateAtten(TableID,Name,Dept,AttendMonth,AttendYear,Month_H,Absent_H,Miss_punch_H,Late_H, Eid_H,train_H,Manager_H,Des_H,Percent,Notes) > 0)
        msg.Text = "updated successfully";
    GridView1.EditIndex = -1;
    GridView1.DataBind();
   // Databind();
 }
private void Databind()
{
     GridView1.DataSource=DA.GetAllAtten();
     GridView1.DataBind();
}

这是此部分的代码(DA.UpdateAtten ... etc:

public int UpdateAtten(string TableID, string Name, string Dept, string AttendMonth, string AttendYear,string Month_H, string Absent_H, string Miss_punch_H, string Late_H, string Eid_H, string train_H, string Manager_H,string Des_H, string Percent,string Notes)
{
    SqlCommand MyCommnd = new SqlCommand("UpdateAttendanceReport", Myconn);

    MyCommnd.CommandType = CommandType.StoredProcedure;
    MyCommnd.Parameters.AddWithValue("@TableID", TableID);
    MyCommnd.Parameters.AddWithValue("@Name",Name);
    MyCommnd.Parameters.AddWithValue("@Dept",Dept);
    MyCommnd.Parameters.AddWithValue("@AttendMonth",AttendMonth);
    MyCommnd.Parameters.AddWithValue("@AttendYear", AttendYear);
    MyCommnd.Parameters.AddWithValue("@Month_H",Month_H);
    MyCommnd.Parameters.AddWithValue("@Absent_H",Absent_H);
    MyCommnd.Parameters.AddWithValue("@Miss_punch_H",Miss_punch_H);
    MyCommnd.Parameters.AddWithValue("@Late_H", Late_H);
    MyCommnd.Parameters.AddWithValue("@Eid_H", Eid_H);
    MyCommnd.Parameters.AddWithValue("@train_H",train_H);
    MyCommnd.Parameters.AddWithValue("@Manager_H",Manager_H);
    MyCommnd.Parameters.AddWithValue("@Des_H",Des_H);
    MyCommnd.Parameters.AddWithValue("@Percent",Percent);
    MyCommnd.Parameters.AddWithValue("@Notes",Notes);
    return MyCommnd.ExecuteNonQuery();
}

0 个答案:

没有答案