需要使用asp.net中的DropDownList来显示名称和图像 [英] Need to Display name and images in dropdownlist using asp.net
问题描述
你好我在dropdownlist.I显示名称和图像都被现在的工作的jquery plugin.Its做到了。
Hi i am displaying Name and image in dropdownlist.I have done it by jquery plugin.Its working now.
我已经从那里数据comes.Here是XML文件的一个节点XML文件。
I have xml file from where data comes.Here is one node of xml file.
<ente>
<name>Sydney</name>
<img>abc_australia.png</img>
<descri>ABC Radio Box 9994 GPO Sydney NSW 2001</descri>
<nazione>AUSTRALIA - AUSTRALIA</nazione>
<latitudine>-33.870652</latitudine>
<longitudine>151.208895</longitudine>
<zoom>-3</zoom>
</ente>
我能够从XML文件取的名字以及与此code绑定的DropDownList:
protected void BindDataToGridviewDropdownlist()
{
XmlTextReader xmlreader = new XmlTextReader(Server.MapPath("XMLFILE.xml"));
DataSet ds = new DataSet();
ds.ReadXml(xmlreader);
xmlreader.Close();
if (ds.Tables.Count != 0)
{
ddlDetails.DataSource = ds;
ddlDetails.DataTextField = "name";
ddlDetails.DataValueField = "name";
ddlDetails.DataBind();
}
}
但在DropDownList中添加图像,我用这个jQuery插件。
But to add images in dropdownlist i used this jquery plugin.
http://www.marghoobsuleman.com/jquery-image-dropdown
在这个插件的图像和数据手动添加是这样的:
In this plugin images and data added manually like this:
<option value='TVSH - Rruga Ismail Quemali 11, Tirana' data-image="images/tvsh-albania.png" data-imagecss="flag ad" data-title="TVSH - Rruga Ismail Quemali 11, Tirana">TVSH - Rruga Ismail Quemali 11, Tirana</option>
我要动态添加绑定下拉列表。(这两个名字和形象)。我拥有的所有图像的图像文件夹中。
I want to add bind dropdown dynamically.(both name and image).I have all images in image folder.
code正在为me.But我想动态绑定下拉列表。
Code is working for me.But i want to bind dropdown dynamically.
有没有办法动态绑定下拉列表。
Is there any way to bind dropdown dynamically.
推荐答案
我会建议,而使用jQuery插件选择二
I would suggest rather using the jQuery plugin Select2
通过选择二则可以使用动态数据源和模板的下拉菜单的选项。
With Select2 you can use a dynamic data source, and template your dropdown's options.
在Selecct2的模板的例子,有样品code作秀一个国家的国旗图片旁边的名字:
Under Selecct2's Templating examples, there is sample code for show an image of a country's flag next to it's name:
function format(state) {
var originalOption = state.element;
return "<img class='flag' src='images/flags/" + state.id.toLowerCase() + ".png' alt='" + $(originalOption).data('foo') + "' />" + state.text;
}
$("#e4").select2({
formatResult: format,
formatSelection: format,
escapeMarkup: function(m) { return m; }
});
我提供的链接,为您提供所需要的所有code样品。
The link I provided provides all the code samples you need.
这是否回答你的问题?
这篇关于需要使用asp.net中的DropDownList来显示名称和图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!