Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net: How to find repeater div in backend?

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

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

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

like image 868
Steven Zack Avatar asked Aug 24 '11 15:08

Steven Zack


2 Answers

HtmlGenericControl defines the methods, properties, and events for all HTML server control elements not represented by a specific .NET Framework class.

So if its a server control you can simply use:

HtmlGenericControl divControl = e.Item.FindControl("divControl") as HtmlGenericControl;
like image 53
CD.. Avatar answered Nov 02 '22 03:11

CD..


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

If you're going to do that, you might as well just use a Panel, as it outputs a DIV anyway.

After doing the above, you should be able to find it like this:

Panel panel = (Panel)Repeater1.Items[0].FindControl("Panel1");
like image 34
James Johnson Avatar answered Nov 02 '22 03:11

James Johnson