Click here to Skip to main content
15,886,518 members

bind a function to image source that embedded in repeater

aminkourosh asked:

Open original thread
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
C#
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.NET
<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>
Tags: C# (C# 2.0, C# 3.0, C# 4.0), SQL Server 2005, ASP.NET, SQL Server

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900