user1511098
user1511098

Reputation: 39

How can I find div control of a repeater in C#?

I am using this div inside a repeater.

<div class="view" id="View"> 

I want this div control in asp.net c# code. This is my code now:

 HtmlGenericControl h3name = null;
 h3name = (HtmlGenericControl)RepeaterView2.Items[count].FindControl("View");
 h3name.Style.Add("width", CHeight.ToString());

But I did not get the control. How can I solve this problem?

Upvotes: 3

Views: 20767

Answers (3)

Alex Dn
Alex Dn

Reputation: 5553

Your div must be with runat = "server" attribute.

Upvotes: 2

Vahid Farahmandian
Vahid Farahmandian

Reputation: 6568

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 sample= e.Item.FindControl("YOURDIVNAME") as HtmlGenericControl;

and also add runet="server" to your div.

Upvotes: 12

chandresh patel
chandresh patel

Reputation: 309

First add a runat server in your div

<div class="view" id="View" runat="server">

now in item bound event of your repeater find it like

HtmlGenericControl sample= e.Item.FindControl("View") as HtmlGenericControl

Upvotes: 2

Related Questions