一个dateview
想从数据库表中读20个记录每行有2列,第一列是图片,第二列是数据请问第一列的图片要怎么绑定?
比如我图片放在image目录下从第一名到20名命为1.jpg--20.jpg请高手指点一下第一列怎么绑定?或者用其它控件也行

解决方案 »

  1.   

    我用的是dateview模板列,,imageurl怎么指定??
      

  2.   

    实际上是绑定一个image控件的imageUrl属性,是个它产生类似这样的结果:
      .ImageUrl="~/showImage.aspx?datakey=1234567"showImage.aspx页面非常简单,大致是:protected void Page_Load(object sender, EventArgs e)
    {
        string recordPrimaryKey = this.Request.QueryString["datakey"];
        char[] myImageData;
        string SQL = "select myImageData from myTable where id=@primaryKey";
        //根据recordPrimaryKey查询数据库,得到图像写入myImageData。
        this.Response.Write(myImageData, 0, myImageData.Length);
        this.Response.End();   //关键
    }
      

  3.   

    都不是,我的图片文件跟从数据库提出的那些数字没关联的
    读出2条记录。。第一条显示1.jpg,第20条显示20.jpg
    图片是文在image文件夹下。。
      

  4.   

    http://www.google.com/search?hl=zh-CN&newwindow=1&rls=com.microsoft%3Aen-US&q=%E7%BB%91%E5%AE%9A+%22imageurl%3D%22+%22%7B0%7D%22&lr=lang_zh-CN%7Clang_zh-TW
      

  5.   

    LZ是这个意思吧ImageUrl="images\Image"+(((GridViewRow)Container).RowIndex+1).ToString()+".gif"
      

  6.   

    楼上的。。你这个语句要放在哪里??
    我代码给你看一下。
            SqlConnection conn = DBconn.openDb();
            SqlCommand mycmd = new SqlCommand("select top 20 title from movie_movie ", conn);
            conn.Open();
            SqlDataReader mysdr = mycmd.ExecuteReader();
            this.GridView1.DataSource = mysdr;
            this.GridView1.DataBind();
    这个是读取数据
                    <Columns>
                        <asp:TemplateField>
                        <ItemStyle Width="40px" />
                            <ItemTemplate>
                                <asp:Image ID="Image1" runat="server" ImageUrl="MyImage/Lxjph/phb-3-1.jpg"/>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <ItemStyle Font-Size="8pt" ForeColor="Gray" HorizontalAlign="Left" Width="160px"  />
                            <ItemTemplate>
                                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="R.aspx" Text='<%# Eval("title") %>'></asp:HyperLink>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
    这是前台页面模板列。。
      

  7.   

    就像是www.5151c.com这页面右边的排行榜是怎么实现的?那个图片怎么实现?
      

  8.   

    邀请人加入  asp.net 开源软件交流群28841212
      

  9.   

    protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                Image image = e.Row.FindControl("image") as Image;            if (image!= null)
                {
                    image.ImageUrl="images\Image"+e.Row.RowIndex+".gif";
                }
            }看看好用么
      

  10.   

    不要忘记前台
    OnRowDataBound="GridView_RowDataBound"
      

  11.   

    image.ImageUrl="images\Image"+(e.Row.RowIndex+1)+".gif";
    sorry 刚才打错了
      

  12.   

    <img src="shoppic/<%# DataBinder.Eval(Container.DataItem, "giftpic")%>"
    我用datalist