-1

How to access the value attribute of a progress tag from back end using asp.net c#.it is not working properly .i need show users percentage based on 5 star and 4 star in div

<div class="stars">

     <span>5 star</span>
     <div class="bar">
     <div class="progress"><asp:Label ID="5star" Text='<%#Eval("5star") %>'></asp:Label></div>
     </div>
        </a>

        <a>
        <span>4 star</span>
        <div class="bar">
        <div class="progress"><asp:Label ID="4star" Text='<%#Eval("4star") %>'></asp:Label></div>
        </div>
        </a>
        </div>

css code:

    .bar{
    background-color: #f2f2f2;
    width: 126px;
    display: inline-block;
    border: 1px solid #f2f2f2;
    height: 12px;

    margin-left: 10px;
    position: relative;
    }
    .progress{
         line-height: 16px;
         height: 15px;
         background-color: #eed44b;
         border: 1px solid #eed44b;
         padding-left: 5px;
    }               
Tushar
  • 3,527
  • 9
  • 27
  • 49
prakash
  • 11
  • 9
  • like 5 star-25% means-----just show color only 25% , 4 star-55% means-----just show color only 55% – prakash Mar 06 '15 at 07:01

3 Answers3

1
  1. The <a> tag which is closed for 5 star doesn't have a starting tag.
  2. Both the label elements should have runat=server set.
  3. The identifier starts with a numeric value which is invalid.
  4. Progress is not a tag. The <div> tag has a class named progress. So I believe you need all the divs which have class set to progress.
  5. Where do you want to show the users percentage and how the ratings would be defined (like click of some button) is also not mentioned. But if it's a label and you want to show it there...

You can use in some click event code like

ShowUsersRatings.InnerHtml = star4.Text;

I have corrected some ASP.NET tags. Please find the correction below

 <div class="stars">
   <a> <!-- added -->
 <span>5 star</span>
 <div class="bar">
 <div runat="server" id="dv1" class="progress"><asp:Label ID="star5" Text='<%#Eval("star5") %>' runat="server"></asp:Label></div>
 </div>
    </a>

    <a>
    <span>4 star</span>
    <div class="bar">
    <div class="progress" id="dv2" runat="server"><asp:Label ID="star4" Text='<%#Eval("star4") %>' runat="server"></asp:Label></div>
    </div>
    </a>
    </div>

    <label id="ShowUsersRatings" runat="server" ></label>

On server side C#/VB you need to get all the <div> elements which have class="progress" and then you need to findControl on a label type. This will give you the exact value.

Mahernoz
  • 79
  • 4
  • There seems to be an incomplete sentence in here at the end of #5. – Nathan Tuggy Mar 06 '15 at 07:49
  • this all ok...but i you did't show color variation(5 star 4star 3 star) based on percenage – prakash Mar 06 '15 at 07:57
  • how to show color variation based on percentage using jquery – prakash Mar 06 '15 at 08:01
  • hi i used

    – prakash Mar 06 '15 at 08:08
  • here how to joint values from back end to div – prakash Mar 06 '15 at 08:08
  • prakash, can you tell me your exact requirements? You mentioned you wanted to access that value using asp.net,c# but now u r asking for jquery support. so please tell what is the exact requirements? both the approaches are different. – Mahernoz Mar 06 '15 at 08:10
  • are you looking for a rating control in jquery? or a progressbar kind of functionality? if you can give some insight to what you need it would be helpful to both of us. – Mahernoz Mar 06 '15 at 08:11
  • i need to show color variation(5 star-25%, 4star-56% ,3 star-80%) based on percenage in different div(5,4,3,2,1 star). – prakash Mar 06 '15 at 08:13
  • If its the ratings control you are looking towards in asp.net then refer http://www.aspsnippets.com/Articles/ASPNet-AJAX-Rating-Control-Example.aspx , if its jquery http://plugins.jquery.com/project/Opineo and if its progressbar then http://jqueryui.com/progressbar/#indeterminate – Mahernoz Mar 06 '15 at 08:14
0

In order to access HTML elements in code-behind you can add the runat="server" attribute to them, like:

<div class="progress" runat="server">
TAMTAM
  • 101
  • 5
  • ok i did.but how to change color varient based on percentage like 5 star 4 star 3 star – prakash Mar 06 '15 at 07:22
  • when i have 25% means how to change color – prakash Mar 06 '15 at 07:23
  • On server side you will work with a HtmlGenericControl - use its Style, InnerHtml, InnerText, Attributes and other properties to implement your logic. See https://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlgenericcontrol%28v=vs.110%29.aspx for details. – TAMTAM Mar 06 '15 at 07:28
  • any example like this – prakash Mar 06 '15 at 07:33
0

If you are looking for a jquery solution. I would recommend you to go JQuery Ratings plugin and look for this solution https://github.com/mre/jquery.ratingbar/blob/master/example_animation.html

This will i hope give you example in JQuery.

Mahernoz
  • 79
  • 4