例如,我使用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事件中传递它?
答案 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;
}
}