同上,radiobuttonlist绑定了图片地址后,怎么让图片显示出来,而不是这个地址字符串...

解决方案 »

  1.   

    要显示图片当然需要类似于image这样的控件
      

  2.   

    首先你最好有个容器,就用Repeater吧页面大致是这样
    <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("图片字段") %>' />
        </ItemTemplate>
    </asp:Repeater>然后绑定你的Repeater即可
      

  3.   

    radiobuttonlist直接绑定图片好像不行,
    不过可以换种方式
    比如在gridview控件的模板列中,同时绑定radiobuttonlist,和图片控件
      

  4.   

    可是单选框怎么和这些图片联系起来啊?
    因为我每一的单选框的value值都不同,用repeater怎么区分呢?
      

  5.   

    比如说文件格式有exe,rar,txt等等
    每个格式有相应的图标
    一个文件只有一个格式
    大概就是这样
    然后选格式
      

  6.   

    没想到好办法,只好逐项绑定了protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindList();
        }
    }private void BindList()
    {
        SqlConnection cn = new SqlConnection(@"server=.\sqlexpress;uid=sa;pwd=;database=northwind");
        SqlCommand cmd = new SqlCommand("select type, url from test", cn);
        cn.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        while(dr.Read())
        {
            RadioButtonList1.Items.Add(new ListItem("<img src='" + dr.GetString(0) + "'", dr.GetString(1)));
        }
        dr.Close();
        cn.Close();
    }
      

  7.   

    我有另外一個方法,欢迎各位指教
    ASP.net 页<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestPage.aspx.cs" Inherits="MeiLeWeb.TestPage" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:RadioButtonList ID="RadioButtonList1" runat="server" DataTextField="ImgeUrl" DataTextFormatString="<img src='{0}'/>" DataValueField="ImgeName" RepeatColumns="3">
            </asp:RadioButtonList></div>
            
        </form>
    </body>
    </html>.cs文件using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Collections.Generic;namespace Demo
    {
        public partial class TestPage : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                ImageInfo img;
                List<ImageInfo> lis = new List<ImageInfo>();
                for (int i = 1; i <= 5; i++)
                {
                    img = new ImageInfo();
                    img.ImgeName = "1";
                    img.ImgeUrl = "App_Themes/Red/Images/bar_0" + i + ".gif";
                    lis.Add(img);
                }
                RadioButtonList1.DataSource = lis;
                RadioButtonList1.DataBind();
            }
        }
        public class ImageInfo
        {
            private string _imgeurl;        public string ImgeUrl
            {
                get { return _imgeurl; }
                set { _imgeurl = value; }
            }
            private string _imgename;        public string ImgeName
            {
                get { return _imgename; }
                set { _imgename = value; }
            }    }
    }
      

  8.   

        <asp:RadioButtonList ID="RadioButtonList2" runat="server" 
                                                   SelectedValue='<%# Bind("taskStatus") %>' CellSpacing="1" 
                                                   DataSourceID="SqlDataSource_taskStatus" DataTextField="image" 
                                                   DataTextFormatString="&lt;img src='{0}'/&gt;" DataValueField="statusID" 
                                                   RepeatDirection="Horizontal" Width="100%">
                                               </asp:RadioButtonList>