我有一个网格视图,每行有三个独立的web用户控件。每个用户控件都包含自己的网格视图。当我重新绑定父网格视图时,我需要能够在用户控件中重新绑定网格视图。正如我现在所拥有的,当我重新绑定父网格时,用户控件中的所有网格都会丢失所有数据。当我重新绑定父网格时,如何访问父网格中的用户控件以重新绑定它们的网格?
发布于 2012-05-25 07:47:12
使用父网格的RowDataBound事件,您可以执行以下操作:
void theParentGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRow row = ((System.Data.DataRowView) e.Row.DataItem).Row;
MyCustomControl custControl1 = e.Row.FindControl("MyCustomControl1Id") as MyCustomControl;
MyCustomControl custControl2 = e.Row.FindControl("MyCustomControl2Id") as MyCustomControl;
MyCustomControl custControl3 = e.Row.FindControl("MyCustomControl3Id") as MyCustomControl;
if (custControl1!=null)
custControl1.bindForRow(row);
if (custControl2!=null)
custControl2.bindForRow(row);
if (custControl3!=null)
custControl3.bindForRow(row);
}
}当然,您的自定义控件的绑定例程将根据row提供的信息在其自己的网格上调用DataBind。
https://stackoverflow.com/questions/10746694
复制相似问题