开发者

Enclosing listbox inside DIV tag

开发者 https://www.devze.com 2023-01-18 13:54 出处:网络
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

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

精彩评论

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

关注公众号