在下拉列表中显示公司名称和徽标

时间:2013-08-09 08:03:26

标签: c# xml vb.net

我想在dropdownlist中显示公司名称和徽标。我已在下拉列表中获取所有公司名称,但我无法添加带名称的徽标。

我有xml文件,其中指定了公司名称和图像。 xml文件的结构:

 <ente>
    <nazione>ALBANIA</nazione>
    <name>Tirana</name>
    <img>tvsh-albania.png</img>
    <descri>TVSH - Rruga Ismail Quemali 11, Tirana</descri>
    <latitudine>41.321102</latitudine>
    <longitudine>19.823112</longitudine>
    <zoom>-4</zoom>
  </ente>

我也在图像文件夹中包含所有图像。

我使用了这段代码:

 Protected Sub BindDataToGridviewDropdownlist()
        Dim xmlreader As New XmlTextReader(Server.MapPath("XMLFILE.xml"))
        Dim ds As New DataSet()
        ds.ReadXml(xmlreader)
        xmlreader.Close()

            If ds.Tables.Count <> 0 Then

                ddlDetails.DataSource = ds

            ddlDetails.DataTextField = "nome"
            ddlDetails.DataValueField = "nome"
            ddlDetails.DataBind()
            End If
    End Sub

我需要做什么,我也可以用公司名称显示图像。

3 个答案:

答案 0 :(得分:0)

开箱即用的

Dropdown列表不支持添加图片。寻找第三方组件。

答案 1 :(得分:0)

我认为在html和.net中很难实现,但使用jQuery插件应该更容易,例如this一个

答案 2 :(得分:0)

使用jQuery试试这个 http://www.htmldrive.net/items/show/749/Image-Select-Elements-with-jQuery-and-CSS3.html

或试试这个 http://designwithpc.com/Plugins/ddSlick

在示例2 .. HTML需要看起来像这样

 <select id="demo-htmlselect">
        <option value="0" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png"
            data-description="Description with Facebook">Facebook</option>
        <option value="1" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png"
            data-description="Description with Twitter">Twitter</option>
        <option value="2" selected="selected" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/linkedin-icon-32.png"
            data-description="Description with LinkedIn">LinkedIn</option>
        <option value="3" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/foursquare-icon-32.png"
            data-description="Description with Foursquare">Foursquare</option>
    </select>

您可以通过绑定到转发器

从Code Behind创建该HTML
<asp:Repeater id="rp" runat="server">
    <HeaderTemplate>
        <select id="demo-htmlselect">
    </HeaderTemplate>

    <ItemTemplate>
        <option value='<%#Container.DataItem("name")%>' data-imagesrc='<%#Container.DataItem("img")%>'
            data-description='<%#Container.DataItem("descri")%>'>
                <%#Container.DataItem("name")%>
        </option>
    </ItemTemplate>

    <FooterTemplate>
    </select>
    </FooterTemplate>
</asp:Repeater>