[英]Gridview is not updating after databind is called
I have 3 gridviews in 3 different updatepanels, which i update them after RowCommand
.我在 3 个不同的更新面板中有 3 个网格视图,我在RowCommand
之后更新它们。
GridView1.DataBind();
GridView2.DataBind();
GridView3.DataBind();
The weird thing is only GridView1_RowCommand
can update all three gridview.奇怪的是只有GridView1_RowCommand
可以更新所有三个 gridview。 GridView2_RowCommand
using the same method but i cannot update the gridview. GridView2_RowCommand
使用相同的方法,但我无法更新 gridview。 Please help me.请帮我。
Thanks in advance.提前致谢。
Here is the code for Rowcommand:这是 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();
}
YES , gridview1_rowcommand
will update all three because if you see the gridview1_rowcommand
.in that method you are calling the databind of other two gridviews also .是的, gridview1_rowcommand
将更新所有三个,因为如果您看到gridview1_rowcommand
该方法中,您也正在调用其他两个 gridviews 的数据绑定。 so now why this happening only while calling gridview1_rowcommand
because you might be probably calling first grid row command or some other Issue.那么现在为什么只在调用gridview1_rowcommand
发生这种情况,因为您可能正在调用第一个网格行命令或其他一些问题。
SO probably Verify whether you getting value in Response.write(id)
所以可能验证您是否在Response.write(id)
获得价值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.