<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对应数据库的图片,但我对这方面真不了解。所以请各位大虾教教!
<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对应数据库的图片,但我对这方面真不了解。所以请各位大虾教教!
ImageUrl=<%# Eval("Pro_Image","~/items/{0}") %>
button2.ImgeUrl=list[1];
...
不知道可不吗
可是 我有翻页啊...照这样的话 我button就要写好多- -
Repeater.DataBind();就可以了 不用循环的
Repeater1.DataBind();
就OK了只要你数据库有Pro_Image这个字段就行了
照意思写了- -调试的时候发现 他会从调试页 Load事件结束后 跳至模板页的Load事件去 这是为什么?
List<Product> p = new List<Product>();
Load()
{
First.DataSource=p;
First.DataBind();
}
就这样最简单的一个,之后就是我发现 我用ImageButton 向上面那样写 我图片读不出来
我直接用<img src='items/<%# Eval("Pro_Image")%>'/>就有图片出来 而且全是相同的
First.DataBind();然后前台绑定注意字段匹配
没用好像 我在页面查看源文件,发现 imagebutton那段代码是乱码!!!
<%@ 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>
<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;" />
这是查看源文件时 看到的代码
正确....因为我用<img src='items/<%# Eval("Pro_Image")%>'/>就有图片出来
我好像写不出来啊 是用FindControl吗?
{
return baseurl+"url";
}
然后前台调用