首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何访问网格视图中的web用户控件?

如何访问网格视图中的web用户控件?
EN

Stack Overflow用户
提问于 2012-05-25 07:33:01
回答 1查看 485关注 0票数 0

我有一个网格视图,每行有三个独立的web用户控件。每个用户控件都包含自己的网格视图。当我重新绑定父网格视图时,我需要能够在用户控件中重新绑定网格视图。正如我现在所拥有的,当我重新绑定父网格时,用户控件中的所有网格都会丢失所有数据。当我重新绑定父网格时,如何访问父网格中的用户控件以重新绑定它们的网格?

EN

回答 1

Stack Overflow用户

发布于 2012-05-25 07:47:12

使用父网格的RowDataBound事件,您可以执行以下操作:

代码语言:javascript
复制
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。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10746694

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档