Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET jQuery
Hello all,
I have a repeater control as below, and I want to show the image button when users selected any other values other than the default Select value.
<asp:Repeater ID="rptSearchUser" runat="server">
                    <HeaderTemplate>
                        <h4>
                            Add Users</h4>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <div class="posSharingUsrList">
                            <div class="pull-left">
                                <asp:Label ID="lblUsername" runat="server" Text='<%#Eval("USER_NAME") %>'></asp:Label>
                            </div>
                            <div class="pull-left selectDiv">
                                <asp:DropDownList ID="ddlUserRoles" runat="server">
                                    <asp:ListItem Value="0">Select Role</asp:ListItem>
                                    <asp:ListItem>Full Control</asp:ListItem>
                                    <asp:ListItem>View only</asp:ListItem>
                                </asp:DropDownList>
                            </div>
                            <div class="pull-right">
                                <asp:ImageButton ID="iBtnShareWithUser" runat="server" CommandArgument='<%#Eval("EMP_ID")%>'
                                    ImageUrl="~/Images/GreenCircle.png" OnClick="iBtnShareWithUser_Click" CssClass="imgPlus" />
                            </div>
                            <div class="clearfix">
                            </div>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
I have tried the following jQuery code to show and hide the image button, but the problem is, if we selected an item from dropdown list, all of the images will display, if the repeater repeats more than one item.
 
 $(function () {
             $("[id$='ddlUserRoles']").change(function () {
                 if (this.value !== "0") {
                     $("[id$='iBtnShareWithUser']").show();
                 } else {
                     $("[id$='iBtnShareWithUser']").hide();
                 }
             });
         });
 
I tried to replace the Image button id with its class, but no luck. How I can get this worked without using autopostback event? Because, I'm using this repeater control inside Bootstrap Modal Popup. I have created a jsbin, if needed for testing.
 
Thanks.
Posted 10-Feb-13 22:12pm
Comments
Irbaz Haider Hashmi at 11-Feb-13 3:58am
   
Try adding dropdown on change function in Repeater OnItemDataBound Event.
Pass Exact values to the Javascript function of the controls you want to show and hide with that particular dropdown.
Ravimallya at 12-Feb-13 0:09am
   
Yeah, Okay. will try to do that. But, if anyone found a jquery solution, that would be great.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can traverse through the control with the help of next().Please have a look on the following example.I have created this by keeping your jsbn example in mind.
$(function () {
 $("select").change(function() {
    if (this.value !== "0") {
      $(this).next().show();
    } else {
      $(this).next().hide();
    }
});
})
  Permalink  
v2

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 520
1 Mathew Soji 335
2 BillWoodruff 260
3 OriginalGriff 215
4 Afzaal Ahmad Zeeshan 188
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,028
3 Manas Bhardwaj 4,539
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 15 Feb 2013
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