开发者

Enclosing listbox inside DIV tag

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:

开发者_StackOverflow

Controls.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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜