Tutorial :Usercontrol with property inside itemtemplate



Question:

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?

update:

If I use usercontrol without the property:

<uc:IdBox id="Idbox1" runat="server"  ShowHeader="True" />  

Databind() is not invoked.


Solution:1

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


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