1
Answer

How to show rating images in gridview

sagar Bhosale

sagar Bhosale

13y
4k
1
HI friends,

I want to show that rating images in my gridview

I have scheme_Name & Rating colunms in my gridviwe i want to display rating images(e.g. *)  in my gridview

i am not storing any images in my database  (in my database rating column have value such as 1,2.3) so accordding this i want to display rating images in  gridview my code is given below

sheme_rating.aspx
<asp:GridView ID="gwdSearchRating" runat="server" Width="100%" AllowPaging="true" CssClass="GridDataCenter" AutoGenerateColumns="false" OnRowDataBound="gwdSearchRating_RowDataBound">
  <Columns>
  <asp:TemplateField>
  <HeaderTemplate>Scheme Name</HeaderTemplate>
  <ItemTemplate>
  <%#DataBinder.Eval(Container.DataItem, "S_Name").ToString()%>
  </ItemTemplate>
  <ItemStyle Width="50%" />
  </asp:TemplateField>
 
  <asp:TemplateField>
  <HeaderTemplate>Rating</HeaderTemplate>
  <ItemTemplate>
  <table>
  <tr>
  <td visible="false"><asp:Label  runat="server" id="lbl_rating" Text='<%#Eval("rating")%>'></asp:Label></td>
  <td runat="server" id="td_rating">
  <asp:Image runat="server" ID="img_rating" ImageUrl="~/Images/rating_stars.png" />
  </td>
  </tr>
  </table>
 
 
  </ItemTemplate>
  <ItemStyle Width="50%" />
  </asp:TemplateField>
 
  </Columns>
  </asp:GridView>

sheme_rating.aspx.cs
protected void gwdSearchRating_RowDataBound(object sender, GridViewRowEventArgs e)
  {
  Label lblrating = (Label)gwdSearchRating.FindControl("lbl_rating");
  Image img = (Image)gwdSearchRating.FindControl("img_rating");
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
 

  int rating = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "rating"));
  for (int i = 0; i < rating; i++)
  {
  string imgcontrol = "<input type='image' >";
  }

  }
  }

from above coding i got rating in this manner 1*,2*,3*
but i want rating *,**, *** in this manner 


plz help me how to do this
thanx

Answers (1)