I want to enclose listbox inside a DIV tag in the code behind file using C#.I am adding all the required attributes and adding the list box as below:
开发者_StackOverflowControls.Add(listBox);
I want the generated listbox to be enclosed with in a div. Please suggest how this can be done.
Thanks in advance.
If the div isn't specified in the form then it can be created in the code behind using the HtmlGeneric class:
HtmlGenericControl myDiv = new HtmlGenericControl { TagName = "div" };
myDiv.Controls.Add(listBox);
this.form1.Controls.Add(myDiv);
Otherwise if the div is already in the HTML just add an id and the runat="server" attibute and add it direclty
HTML:
<div id="myDiv" runat="server"></div>
code behind:
myDiv.Controls.Add(listBox);
精彩评论