C# 下拉列表中的图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1079112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 07:42:48  来源:igfitidea点击:

Images in dropdown list

c#asp.netdrop-down-menu

提问by Nagu

Hi I want to put image along with some data in asp.net drop down list box.

嗨,我想将图像和一些数据放在 asp.net 下拉列表框中。

Can somebody give me a sample code to achieve this functionality?

有人可以给我一个示例代码来实现这个功能吗?

country flag + country name --> in the same list item

country flag + country name --> 在同一个列表项中

回答by Canavar

With standart dropdownlist, you can not achive this.

使用标准下拉列表,您无法做到这一点。

You need to write a custom server control that is not based on dropdown list.

您需要编写一个不基于下拉列表的自定义服务器控件。

回答by hadi teo

I haven't tried to use this JQuery Combo-Box,but from the screenshot, it looks like the items in the combo box can include an image in it. Maybe you could research more regarding this.

我没有尝试使用这个JQuery Combo-Box,但从屏幕截图来看,看起来组合框中的项目可以在其中包含图像。也许您可以对此进行更多研究。

回答by JaredPar

You cannot achieve this with a raw drop down list / combo box in C#. The underlying control only supports text and not a combination of text + image.

您无法使用 C# 中的原始下拉列表/组合框来实现此目的。底层控件仅支持文本,不支持文本+图像的组合。

You'll either need to write a custom control or use something like jQuery to build the drop down with your code populating the results.

您要么需要编写自定义控件,要么使用 jQuery 之类的东西来构建下拉列表,并使用您的代码填充结果。

回答by Seb Nilsson

You could use jQuery Image Dropdown:

您可以使用jQuery Image Dropdown

http://marghoobsuleman.com/jquery-image-dropdown

http://marghoobsuleman.com/jquery-image-dropdown

jQuery Image Dropdown
(source: marghoobsuleman.com)

jQuery 图像下拉菜单
(来源:marghoobsuleman.com

<script language="javascript">    
$(document).ready(function(e) {
    try {
        // target some ids
        MSDropDown.init("#combo1, #combo2");
        //by wild card
        MSDropDown.init("#divid select");
        //or 
        MSDropDown.init("#formid select");
    } catch(e) {
    alert(e);
    }
})
</script>

回答by Hassan Osman

That's right, standard tool doesn't accept images, try with a custom tool.

没错,标准工具不接受图像,请尝试使用自定义工具。

try with this free tool: http://controlsbuilder.com/tools/CustomDropDownList.aspx

尝试使用这个免费工具:http: //controlsbuilder.com/tools/CustomDropDownList.aspx

回答by Atta Ur Rahman

Try this, it's one of the best solution.... and easiest
http://www.obout.com/combobox/icons/aspnet_icons_database.aspx

试试这个,它是最好的解决方案之一......也是最简单的
http://www.obout.com/combobox/icons/aspnet_icons_database.aspx