-1
我在3個不同的更新面板中有3個gridview,我在RowCommand
之後更新它們。在調用數據綁定後Gridview沒有更新
GridView1.DataBind();
GridView2.DataBind();
GridView3.DataBind();
奇怪的是隻有GridView1_RowCommand
可以更新所有三個gridview。 GridView2_RowCommand
使用相同的方法,但我不能更新gridview。 請幫幫我。
在此先感謝。
這裏是Rowcommand代碼:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
//check the commandName
if (e.CommandName != "SaveStartTime")
return;
int rowIndex = int.Parse(e.CommandArgument.ToString());
string id = GridView1.Rows[rowIndex].Cells[0].Text;
Label time = GridView1.Rows[rowIndex].Cells[4].FindControl("ActualTimeStart") as Label;
time.Text = DateTime.Now.ToString("HH:mm");
var Cn = new System.Data.SqlClient.SqlConnection();
Cn.ConnectionString = "Server=.\\SqlExpress;Database=CMOS;Trusted_Connection=True";
Cn.Open();
var Cm = Cn.CreateCommand();
string store = string.Format(@"UPDATE [ApprovedExitPass] SET ActualTimeStart = '{0}' WHERE Id='{1}'", time.Text, id);
SqlCommand cmd = new SqlCommand(store, Cn);
cmd.Parameters.AddWithValue("@ActualTimeStart", time.Text);
cmd.ExecuteNonQuery();
Cn.Close();
GridView1.DataBind();
GridView2.DataBind();
GridView3.DataBind();
}
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
{
//check the commandName
if (e.CommandName != "SaveReturnTime")
return;
int rowIndex = int.Parse(e.CommandArgument.ToString());
string id = GridView2.Rows[rowIndex].Cells[0].Text;
Response.Write(id);
Label time = GridView2.Rows[rowIndex].Cells[4].FindControl("ActualTimeArrive") as Label;
time.Text = DateTime.Now.ToString("HH:mm");
var Cn = new System.Data.SqlClient.SqlConnection();
Cn.ConnectionString = "Server=.\\SqlExpress;Database=CMOS;Trusted_Connection=True";
Cn.Open();
var Cm = Cn.CreateCommand();
string store = string.Format(@"UPDATE [ApprovedExitPass] SET ActualTimeArrive = '{0}' WHERE Id='{1}'", time.Text, id);
SqlCommand cmd = new SqlCommand(store, Cn);
cmd.Parameters.AddWithValue("@ActualTimeArrive", time.Text);
cmd.ExecuteNonQuery();
Cn.Close();
GridView1.DataBind();
GridView2.DataBind();
GridView3.DataBind();
}
獲得價值請添加更多的代碼,包括'GridView1_RowCommand'。 –
根據你發佈的內容很難確定你所看到或看不到的內容。請編輯此問題併發布所有相關的代碼,方法和事件。 – MethodMan
我更新了代碼。兩個使用相同的更新方法,但只有'GridView1_RowCommand'可以更新所有3個gridview。 – Wen21