日期:2014-05-19  浏览次数:20587 次

Repeater添加图片问题!
我的cs   文件代码如下!
private   void   BindGood()
{
string   strsql   =   @ "select   top   5   ( 'BBS_ReferList.aspx?SectionId= '+CAST   (S.SectionID       as   varchar(14)))   as   url   ,S.SectionName,   R.Hits
from   BBS_Sections   as   S   Inner   Join   (select   top   5   SectionID,Hits   from   BBS_Refers   order   by   Hits   desc)   as     R   On   S.SectionID   =   R.SectionID ";
DataSet   objds   =   new   DataSet();
objds   =   SqlHelper.ExecuteDataset(Operate.SqlConn,CommandType.Text,strsql);
try
{
Repeater1.DataSource   =   objds.Tables[0];
Repeater1.DataBind();
}
catch(Exception   error)
{
Response.Write(error.ToString());
}
}
页面邦定代码如下:
<asp:repeater   id= "Repeater1 "   runat= "server ">
<ItemTemplate>
<asp:Image   id= "Image2 "   runat= "server "   ImageUrl= "../image/bbs_1.gif "   Width= "14px "   Height= "15px "> </asp:Image>
<a   href= ' <%#DataBinder.Eval(Container.DataItem, "url ")%> '>
<%#DataBinder.Eval(Container.DataItem, "SectionName ")%>
</a> ( <%#DataBinder.Eval(Container.DataItem, "Hits ")%> )
<br>
</ItemTemplate>
</asp:repeater>

我现在想做的事情是Repeater每换一行输出数据我就把前面的图片换成另外一个
image/bbs_1.gif;
也就是说,Repeater如果输出5行数据(每行一列)的话!平时前面会有5个一样的图标。我想把把这个图片换成5   个不同的图片。。。怎么办?谢谢!

------解决方案--------------------
<%@ Page language= "c# " Codebehind= "WebForm1.aspx.cs " AutoEventWireup= "false " Inherits= "WebApplication16.WebForm1 " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN " >
<HTML>
<HEAD>
<title> WebForm1 </title>
<meta name= "GENERATOR " Content= "Microsoft Visual Studio .NET 7.1 ">
<meta name= "CODE_LANGUAGE " Content= "C# ">
<meta name= "vs_defaultClientScript " content= "JavaScript ">
<meta name= "vs_targetSchema " content= "http://schemas.microsoft.com/intellisense/ie5 ">
</HEAD>
<body>
<form runat= "server ">
<asp:Repeater ID= "Repeater1 " runat= "server ">
<ItemTemplate>
<div>
<asp:Image ID= "Image2 " runat= "server " ImageUrl= " " Width= "14px " Height= "15px "> </asp:Image>
<%#DataBinder.Eval(Container.DataItem, "Title ")%>
</div>
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</HTML>


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication16
{
/// <summary>