将 Dropdownlist 与来自 sql 数据源的 optGroup 绑定
我必须将下拉列表与应按区域分组的国家绑定,我从以下链接找到了示例代码,
http://www.codeproject.com/KB/custom-controls/DropDownListOptionGroup.aspx?msg=3984074#xx3984074xx
我希望国家/地区列表与此相同。但问题是我想从 sql 结果绑定下拉列表。我尝试过以下方法,但没有成功,
ddlCountry.DataSource = CountryDtoCollection;
ddlCountry.DataBind();
ddlCountry.Attributes.Add("OptionGroup", "Region");
任何人都知道解决方案。
I have to bind a Dropdownlist with coutries which should be grouped by region, I have found a sample code from the following link,
http://www.codeproject.com/KB/custom-controls/DropDownListOptionGroup.aspx?msg=3984074#xx3984074xx
I wanted the country list same as this. But problem is that I want to bind the dropdownlist from sql result. I have tried the following but didn't work,
ddlCountry.DataSource = CountryDtoCollection;
ddlCountry.DataBind();
ddlCountry.Attributes.Add("OptionGroup", "Region");
any one knows any solution for this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以编写自定义服务器控件并使用包含由 | 分隔的文本和区域的数据源,然后在使用时将其拆分。
you can write a custom server control and use the data source witch containing the text and region separated by | then split it when use.