本文介绍了无法正确绑定嵌套网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个嵌套网格(父网格1,子网格2)。我在行命令事件上显示grid2 grid1。我试图在grid2的rowcommand事件上更新grid2,但它没有正确绑定。我通过断点发现最新的reocrds绑定grid2但它没有显示最新的记录。
Hi,
I have a nested grid(parent grid1,child grid2).i am displaying grid2 on row command event of grid1. I am trying to update grid2 on rowcommand event of grid2 but its not binding properly. I found through breakpoint that latest reocrds are binding grid2 but it is not displaying latest records.
推荐答案
protected void ParentGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Update")
{
ImageButton img = (ImageButton)e.CommandSource as ImageButton;
GridViewRow row = img.NamingContainer as GridViewRow;
GridView chil= (GridView )row.FindControl("ChildgridId");
SqlCommand cmd=new SqlCommand("select * from table",connectionstring);
Dataset ds;
SqlDataAdapter ad=new SqlDataAdapter(cmd);
ad.Fill(ds);
Bind the values from the query to Chil datasource
chil.DataSource=ds;
chil.DataBind();
}
}
这篇关于无法正确绑定嵌套网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!