views:

34

answers:

2

I have a div with id="myDiv" and runat="server" inside a listview with id="lvItem".I need to access the div in code behind to add width of the div at runtime.How can I access the div from codebehid using C#?Can anyone help me?

A: 

Just add an Asp:Panel instead. Asp:Panel in ASP.NET = DIV on the front end.

So basically this would be your code

ASP.NET

<asp:Panel id="myDiv" runat="server">
</asp:Panel>

Code Behind

Panel myDiv = (Panel)myListView.FindControl("myDiv");
myDiv.Attributes.Add("style", "width: 100px");
Marko
this does not work
andrew Sullivan
A: 
 <div id="coolmenu" runat="server">
 </div>   

 HtmlControl htmlDivControl = (HtmlControl)Page.FindControl("coolmenu");
 (htmlDivControl.Style["width"]) ="30px";
anishmarokey