asp.net C#Gridview嵌套Gridview
亲爱的天才们,请帮我解决这个问题。我到处都在尝试,但运气不佳。我试图打开一个父行的嵌套gridview,但却打开了整个父行和子行的一条记录。当我单击父gridview行的按钮时,特定行的记录应显示在同一父行的子gridview中,但在我的情况下,父行的记录将显示,并且子gridview将在所有父行中打开。如需帮助,请:(asp.net C#Gridview嵌套Gridview,c#,asp.net,gridview,C#,Asp.net,Gridview,亲爱的天才们,请帮我解决这个问题。我到处都在尝试,但运气不佳。我试图打开一个父行的嵌套gridview,但却打开了整个父行和子行的一条记录。当我单击父gridview行的按钮时,特定行的记录应显示在同一父行的子gridview中,但在我的情况下,父行的记录将显示,并且子gridview将在所有父行中打开。如需帮助,请:( 您正在循环GridView4中的所有行,因此每个嵌套的GridView都将填充数据。 您需要的是单击的链接按钮所在行的行号,并使用该行号查找嵌套的GridView prote
您正在循环
GridView4
中的所有行,因此每个嵌套的GridView都将填充数据。
您需要的是单击的链接按钮所在行的行号,并使用该行号查找嵌套的GridView
protected void blah_Command(object sender, CommandEventArgs e)
{
//get the current datagrid item from the sender
GridViewRow row = (GridViewRow)(((Control)sender).NamingContainer);
//the row index of the gridviewrow
int rowIndex = row.RowIndex;
//find the correct nested grid using the row index
GridView gvOrders = GridView4.Rows[rowIndex].FindControl("gvOrders") as GridView;
}
代码基本正确。请在查询中使用参数。首先,为什么要编写:
foreach(GridView4.Rows中的GridViewRow2)
?使用发送方和相对容器而不是该代码。如果无法修复,您是否可以尝试在不使用ImageButton的RowDataBound事件中完成所有操作?我建议您改变思维方式:GridvView很难以这种方式使用。您可以使用覆盖(thickbox、colorbox…)然后在其中打开嵌套的GridView。或者您执行目标客户端…@Emanuele谢谢,让我检查并重试。受保护的void blah_命令(对象发送方,CommandEventArgs e){ImageButton imgshow=(发送方作为ImageButton);GridViewRow=(imgshow.NamingContainer作为GridViewRow);row.FindControl(“pLorders”).Visible=true;GridView gvOrders=GridView4.Rows[rowIndex].FindControl(“gvOrders”)作为GridView;字符串customerId=e.CommandName.ToString();BindOrders(customerId,gvOrders);}
protected void blah_Command(object sender, CommandEventArgs e)
{
foreach (GridViewRow row2 in GridView4.Rows)
{
row2.FindControl("pnlOrders").Visible = true;
string customerId = e.CommandName.ToString();
GridView gvOrders = row2.FindControl("gvOrders") as GridView;
BindOrders(customerId, gvOrders);
}
}
private void BindOrders(string customerId, GridView gvOrders)
{
gvOrders.ToolTip = customerId;
gvOrders.DataSource = GetData(string.Format("select * from SShare where UId='{0}'", customerId));
gvOrders.DataBind();
}
protected void blah_Command(object sender, CommandEventArgs e)
{
//get the current datagrid item from the sender
GridViewRow row = (GridViewRow)(((Control)sender).NamingContainer);
//the row index of the gridviewrow
int rowIndex = row.RowIndex;
//find the correct nested grid using the row index
GridView gvOrders = GridView4.Rows[rowIndex].FindControl("gvOrders") as GridView;
}