Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 C#2.0 C#3.0 C# , +
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>
Posted 1-Aug-12 23:37pm
Edited 3-Aug-12 21:26pm
v4
Comments
pradiprenushe at 2-Aug-12 4:51am
   
Post source code for repeater.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Think about it for a minute. You have a loop. This is DIFFERENT to the loop the repeater is running in. But, inside that loop is a return statement. If you knew how to use a debugger, you'd have noticed that only the first iteration of this loop is ever run. So, you need to get rid of the loop, and instead pass in the data element to the method, so each row will work with the data from that row.
 
I believe you need to pass in Container.DataItem, and then cast it and find the data you want in your code from that row.
  Permalink  
Comments
aminkourosh at 2-Aug-12 4:45am
   
I know that my code is completely wrong . but i have any nice code for edit it.if you can help me i will be glad
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try to use the ajax call for your getimg() method and pass the ranking value as parameter and update your image source with Jquery..this solution will be easy for you..
OR
Create a DTO for your template and map that value to the Expression in Repeater.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 4 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100