Tutorial :Usercontrol with property inside itemtemplate


I am looking 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?


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:


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »