I have a repeater that it has image inside itself. I want to show different image base on ranking for example if ranking is 1 I show an image and if it is 2 I show the other etc.and i have 5 kind of image and 5 grade too.
Ranking is a column in dataset. But my function does not work correctly and I can't get correct result. It only shows first pic. What solution do you suggest for this operation??
thank a lot.
This is my code
public string getimg()
{
SqlConnection con = new SqlConnection("data source=.;database=site;integrated security=true;");
string sSQL = "Select username ,weight,point , Rank() over(order by point desc) as 'ranking' from karbar order by point desc";
SqlCommand cmd = new SqlCommand(sSQL, con);
SqlDataAdapter adapt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapt.Fill(ds);
foreach (DataRow myRow in ds.Tables[0].Rows)
{
if (Convert.ToInt32(myRow["ranking"]) == 1)
{ return "price/con1.png"; }
else return "price/con2.png";
}
}
and its html
<asp:Repeater ID="rptList" runat="server" OnItemDataBound="rptList_ItemDataBound">
<HeaderTemplate>
<table>
<tr>
<th>
</th>
<th>
<asp:Label ID="Label14" Text="point" runat="server"></asp:Label>
</th>
<th>
<asp:Label ID="Label1" Text="whight" runat="server"></asp:Label>
</th>
<th>
<asp:Label ID="Label2" Text="average" runat="server"></asp:Label>
</th>
<th>
<asp:Label ID="Label3" Text="ranking" runat="server"></asp:Label>
</th>
<th>
<asp:Label ID="Label6" Text="name" runat="server"></asp:Label>
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<div class="outer">
<div class="inner">
<div class="innerContent" style=" width: 53px; text-align:center">
<%#DataBinder.Eval(Container.DataItem,"point") %>
</div>
<div class="innerContent" style=" width: 53px; text-align:center" ">
<%#DataBinder.Eval(Container.DataItem,"weight") %>
</div>
<div class="innerContent" style=" width: 53px; text-align:center">
<%#DataBinder.Eval(Container.DataItem,"average") %>
</div>
<div class="innerContent" style=" width: 140px; text-align:center">
<asp:Label ID="Label7" runat="server" Text='<%# Eval("username") %>' Width="138"></asp:Label>
</div>
<div class="innerContent" style=" width: 53px; text-align:center">
<%#DataBinder.Eval(Container.DataItem, "ranking")%>
</div>
<div class="innerTitle">
<img style="width:53px;height:52px" alt="" src="<%# getimg() %>" /></div>
</div>
<div class="clear">
</div>
</div>
</div>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>