<asp:Repeater ID="First" runat="server">
                     <ItemTemplate>
                         <div class="pad-10">
                            <table style="height: 277px; width: 1000px" >
                            <tr>
                            <td rowspan="2" class="style15" >                   
                                 <asp:ImageButton ID="Cai1" runat="server" Height="270px" 
                                    Width="321px"  ImageUrl='~/items/<%# Eval("Pro_Image") %>'/>
                            </td>
                            <td class="style11" >
                                <asp:ImageButton ID="Cai2" runat="server" Height="136px" 
                                    Width="187px" ImageUrl='~/items/<%# Eval("Pro_Image") %>'/>
                                </td>
                            <td class="style12" ><asp:ImageButton ID="Cai3" runat="server" Height="136px" 
                                    Width="187px" ImageUrl='~/items/<%# Eval("Pro_Image") %>'/></td>
                            <td class="style13" ><asp:ImageButton ID="Cai4" runat="server" Height="136px" 
                                    Width="187px" ImageUrl='~/items/<%# Eval("Pro_Image") %>'/></td>
                            </tr>
                            <tr>
                            <td class="style9" >
                                <asp:ImageButton ID="Cai5" runat="server" Height="136px" 
                                    Width="187px" ImageUrl='~/items/<%# Eval("Pro_Image") %>'/>
                                </td>
                            <td class="style10" ><asp:ImageButton ID="Cai6" runat="server" Height="136px" 
                                    Width="187px" ImageUrl='~/items/<%# Eval("Pro_Image") %>'/></td>
                            <td class="style14" ><asp:ImageButton ID="Cai7" runat="server" Height="136px" 
                                    Width="187px" ImageUrl='~/items/<%# Eval("Pro_Image") %>'/></td>
                            </tr>
                          </table>
                         </div>
                     </ItemTemplate>
                 </asp:Repeater>
我想通过数据库,从后台绑定,让每个ImageButton对应数据库的图片,但我对这方面真不了解。所以请各位大虾教教!

解决方案 »

  1.   

    你写的对的啊  不过还有一种写法  
           
                   ImageUrl=<%# Eval("Pro_Image","~/items/{0}") %>
      

  2.   

    对的?后台怎么写呢? 我数据库里存的是  varchar 名字.png 我先获取所有 存到集合  然后遍历 得到图片 可是控件有7个  这时候 foreach里就不知道该怎么写了   
      

  3.   

    不好意思    我理解错了,  我看了一下,你可以不用Repeater的,页面上只是表格,然后cs文件里面  分别给七个button 绑定就完了,七个也不多,
      

  4.   

    button1.ImgeUrl=list[0];
    button2.ImgeUrl=list[1];
    ...
    不知道可不吗
      

  5.   


    可是 我有翻页啊...照这样的话  我button就要写好多- -
      

  6.   

    晕死 你直接一个TD 就可以了  得到集合 就绑定Repeater.DataSource=集合
    Repeater.DataBind();就可以了 不用循环的
      

  7.   

    Repeater1.DataSource=查出来的数据集合
    Repeater1.DataBind();
    就OK了只要你数据库有Pro_Image这个字段就行了
      

  8.   


    照意思写了- -调试的时候发现  他会从调试页 Load事件结束后 跳至模板页的Load事件去 这是为什么?
      

  9.   


    List<Product> p = new List<Product>();
    Load()
    {
       First.DataSource=p;
       First.DataBind();
    }
    就这样最简单的一个,之后就是我发现 我用ImageButton 向上面那样写 我图片读不出来
    我直接用<img src='items/<%# Eval("Pro_Image")%>'/>就有图片出来 而且全是相同的
      

  10.   

    你的集合P貌似都没有数据、 repeater有数据显示吗?给你个例子 希望有用First.DataSource = Product.getAllPro();//查出所以商品的方法
    First.DataBind();然后前台绑定注意字段匹配
      

  11.   

    直接把图片地址写入Pro_Image字段,读取时让它显示出来就好了。像你上面那样已经是显示数据了。
      

  12.   


    没用好像  我在页面查看源文件,发现 imagebutton那段代码是乱码!!!
      

  13.   

    imagebutton那段代码 前台代码 和后台代码 贴出来 和生成后的html代码等
      

  14.   


    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm5.aspx.cs" Inherits="Restaurant.WebForm5" %><!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">
            <asp:Repeater ID="First" runat="server">
                         <ItemTemplate>
                             <div class="pad-10">
                                <table style="height: 277px; width: 1000px" >
                                <tbody>
                                <tr>
                                <td rowspan="2" class="style15" >  
                                    <asp:ImageButton ID="Cai1" runat="server" Height="270px" 
                                        Width="321px"  ImageUrl='~/items/<%# Eval("Pro_Image") %>'/>                 
                          
                                </td>
                                </tr>
                              <tbody>
                          </table>
                        </div>
                       </ItemTemplate>
                      </Repeater >
                     </form>
      

  15.   


    <input type="image" name="First$ctl00$Cai1" id="First_Cai1_0" src="items/%3C%25#%20Eval(%22Pro_Image%22)%20%25%3E" style="height:270px;width:321px;" /> 
    这是查看源文件时 看到的代码
      

  16.   

    <input type="image" name="First$ctl00$Cai1" id="First_Cai1_0" src="items/%3C%25#%20Eval(%22Pro_Image%22)%20%25%3E" style="height:270px;width:321px;" /> 这是查,看源,文件看到的代码
      

  17.   

    ImageUrl='/items/<%# Eval("Pro_Image") %>'/> 或者../试试 ImageUrl='<%# Eval("Pro_Image") %>'/>是否会被转义
      

  18.   

    首先保证List里面的数据是否正确
      

  19.   


    正确....因为我用<img src='items/<%# Eval("Pro_Image")%>'/>就有图片出来 
      

  20.   


    我好像写不出来啊  是用FindControl吗?
      

  21.   

    后台写个 public string geturl(string url)
    {
        return baseurl+"url";
    }
    然后前台调用