Asp.net: How to find a div repeater in the backend?

I use a repeater to display records from the database, especially I use a div tag to display the html content stored in datatable. But I do not know how to find the div in the backend. In the Repeater_ItemDataBound event, I can use

Control divControl=e.Item.FindControl("divControl"); 

to get it, but it does not have the innerHtml property to set the html content. Does anyone know how to get it as a div control?

+7
source share
2 answers

The HtmlGenericControl defines methods, properties, and events for all HTML server controls that are not represented by a specific .NET Framework class.

So, if its server-side control can simply be used:

 HtmlGenericControl divControl = e.Item.FindControl("divControl") as HtmlGenericControl; 
+7
source

To find the DIV in the code behind, you need to add the runat="server" tag in the DIV.

If you are going to do this, you can just use Panel , as it still displays a DIV.

After doing the above, you can find it as follows:

 Panel panel = (Panel)Repeater1.Items[0].FindControl("Panel1"); 
+1
source

All Articles