locked
Hide show image button based on other column values RRS feed

  • Question

  • Hi,

    I have a Grid View where i have 2 columns(Rating and star).In star column Iam showing 5 imagebuttons.What i want is if rating is 1 I want only one star(image button) to be visible,if rating is 2 then 2 image buttons and similarly till 5.
    Below is my image templatefield



    <asp:TemplateField>
    <ItemTemplate>
                                       
                                            <asp:ImageButton ID="ImageButton" runat="server" ImageUrl="/eur/Home/OfferLetter/images/delete_icon.gif" CausesValidation="false" />                                       
                                            <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="/eur/Home/OfferLetter/images/delete_icon.gif" CausesValidation="false" />
                                            <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="/eur/Home/OfferLetter/images/delete_icon.gif" CausesValidation="false" />
                                            <asp:ImageButton ID="ImageButton3" runat="server"  ImageUrl="/eur/Home/OfferLetter/images/delete_icon.gif" CausesValidation="false" />
                                            <asp:ImageButton ID="ImageButton4" runat="server" ImageUrl="/eur/Home/OfferLetter/images/delete_icon.gif" CausesValidation="false" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
    Tuesday, February 4, 2014 3:47 AM

Answers

  • Hi, Hasan712.

    Just a suggestion; I think you should have five different image files of the stars in your /images/ folder. Each image will include a number of stars in it - one to five stars.  As well, you will only need one <asp:ImageButton> control.

    Then all you have to do is set the ImageUrl to the path and name of the image file for each row. That can be based on your query results from the database.

    Are you sure you want to use an ImageButton instead of just an <asp:Image> control? You only need an ImageButton control if you are going to create a click event hander for on the stars.  

    Alternately, please know that Microsoft's Ajax Control Toolkit includes (among 50+ free web controls) a Star Rating Web control that you use to allow web users to rate things. There may be some compatibility issues with some web browsers so be sure to test it! Here they are:
    http://ajaxcontroltoolkit.codeplex.com/

    I think you accidently asked this question on the wrong Microsoft forum. This is the Microsoft Training and Certification forum. You will probably get a better answer if you ask your question here:
    http://forums.asp.net/24.aspx/1?Web+Forms+Data+Controls

    Good luck!


    Best wishes, Davin Mickelson

    Tuesday, February 4, 2014 7:08 AM
    Answerer

All replies

  • Hi, Hasan712.

    Just a suggestion; I think you should have five different image files of the stars in your /images/ folder. Each image will include a number of stars in it - one to five stars.  As well, you will only need one <asp:ImageButton> control.

    Then all you have to do is set the ImageUrl to the path and name of the image file for each row. That can be based on your query results from the database.

    Are you sure you want to use an ImageButton instead of just an <asp:Image> control? You only need an ImageButton control if you are going to create a click event hander for on the stars.  

    Alternately, please know that Microsoft's Ajax Control Toolkit includes (among 50+ free web controls) a Star Rating Web control that you use to allow web users to rate things. There may be some compatibility issues with some web browsers so be sure to test it! Here they are:
    http://ajaxcontroltoolkit.codeplex.com/

    I think you accidently asked this question on the wrong Microsoft forum. This is the Microsoft Training and Certification forum. You will probably get a better answer if you ask your question here:
    http://forums.asp.net/24.aspx/1?Web+Forms+Data+Controls

    Good luck!


    Best wishes, Davin Mickelson

    Tuesday, February 4, 2014 7:08 AM
    Answerer
  • Hello Hasan,

    For gridview we have rowcreated and rowdatabound events. in side any of these event you can write below code to hide other imagebuttons.

    Ife.Row.RowType = DataControlRowType.DataRow Then

    select case DataBinder.Eval(e.Row.DataItem, "Rating").ToString

    case "1"

    Hide first image button

    case "2"

    Hide second image button

    ......... and so on for all rating values

    end select

    Tuesday, February 4, 2014 7:14 AM