Can anyone recommend a dropdownlist control for asp.net (3.5) that can render option groups? Thanks
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- Request.PathInfo issues and XSS attacks
- How to dynamically load partial view Via jquery aj
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- “Dynamic operations can only be performed in homog
- What is the best way to create a lock from a web a
- Add to htmlAttributes for custom ActionLink helper
Based on the posts above I've created a c# version of this control with working view state.
I hope this helps some people :-)
I use the reflector to see why is not supported. There is why. In the render method of the ListControl no condition is there to create the optgroup.
So i create my own dropdown Control with an override of the method RenderContents. There is my control. Is working fine. I use exactly the same code of Microsoft, just add a little condition to support listItem having attribute optgroup to create an optgroup and not a option.
Give me some feed back
Thanks Joel! everyone... here's C# version if you want it:
Tested on Chrome 16, Firefox 9 and IE8.
I've done this using an outer repeater for the select and optgroups and an inner repeater for the items within that group:
The data source for
outerRepeater
is a simple grouping as follows:And to get the alpha grouping character:
It's not a perfect solution but it works. The correct solution would be to no longer use WebForms, but us MVC instead. :)
The above code renders the end tag for the optgroup before any of the options, so the options don't get indented like they should in addition to the markup not properly representing the grouping. Here's my slightly modified version of Tom's code:
Use it like this:
and here's the generated markup (indented for ease of viewing):