7

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?

Steven Zack
  • 4,554
  • 19
  • 52
  • 84

2 Answers2

8

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;
CD..
  • 65,131
  • 24
  • 138
  • 151
1

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");
5377037
  • 9,493
  • 12
  • 43
  • 73
James Johnson
  • 43,670
  • 6
  • 67
  • 106