Click here to Skip to main content
15,903,836 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.NET
<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.

JavaScript
$(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
Comments
Irbaz Haider Hashmi 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 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

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();
    }
});
})
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900