I am lo开发者_如何学Coking on some example and can't understand the following:
There is a gridview, inside it's itemtemplate is a use control:
<asp:TemplateField>
<ItemTemplate>
<%# Eval("Title") %>
<uc:IdBox id="Idbox1" runat="server" TheID='<%# Eval("ID") %>' ShowHeader="True" />
</ItemTemplate>
</asp:TemplateField>
There is also ObjectDataSource connected to the gridview.
My question is why TheID='<%# Eval("ID") %>'
invokes public override void DataBind()
that is overrided in this User control code behind?
I thought that this value is evaluated just as ObjectDataSource connects to gridview and this TheID property should get the valu from the ObjectDataSource.
Why it needs to call DataBind() of the user control?
update:
If I use usercontrol without the property:
<uc:IdBox id="Idbox1" runat="server" ShowHeader="True" />
Databind() is not invoked.
Interesting... are you explicitly binding data, or just setting a DataSourceID? When you are using an ObjectDataSource, ASP.NET internally calls DataBind automatically.
The following MSDN article may help:
http://msdn.microsoft.com/en-us/library/ms178366.aspx
精彩评论