如何将重复对象传递给用户控件到转发器

时间:2013-01-11 12:23:21

标签: asp.net telerik-grid datarepeater

例如,我使用telerik rad grid,并将用户列表绑定到它

rgUsers.DataSource = GetUsersList();
rgUsers.DataBind();

我有用户控件 UserEditor ,它接收用户对象

<radG:RadGrid runat="server" ID="rgUsers">
    <MasterTableView>
        <Columns>
          <radG:GridTemplateColumn>
              <ItemTemplate>
                  <asp:Label runat="server" ID="lblName" Text='<%# Eval("username") %>'></asp:Label>
              </ItemTemplate>
              <EditItemTemplate>
                <uc:UserEditor ID="UserEditor" runat="server" User='???????' />
              </EditItemTemplate>
          </radG:GridTemplateColumn>
          ... 

我可以将User对象传递给 UserEditor ,还是必须在Data Binding事件中传递它?

1 个答案:

答案 0 :(得分:2)

我认为它就像本机ASP.NET控件一样:

RadControls for ASP.NET AJAX Documentation - Event sequence

<radG:RadGrid runat="server" ID="rgUsers" OnItemDataBound="rgUsers_ItemDataBound">  

protected void rgUsers_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item.ItemType == GridItemType.EditItem) 
    {
        User user = (User)e.Item.GridDataItem;
        UserEditor userEditor = (UserEditor )e.Item.FindControl("UserEditor");
        UserEditor.User = user;
    }

}