Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have dropdown list yes or no if yes is selected after saving then edit button in record in the grid view should disappear if yes is selected,,in javascript or jquery,,any help please
ASP.NET
<div class="controls">
                                <asp:DropDownList ID="ddMovetoStore" CssClass="input-large"  runat="server">
                                <asp:ListItem Text="No" Value="No">
                                <asp:ListItem Text="Yes" Value="Yes">
                                
                                <br />
                                <span style="color:Red; font-size:10px;">By selecting yes you will not be able to edit or delete this record</span>
                            </div>

grid view button edit:
ASP.NET
<itemtemplate>
                                 <%--   <% if container.dataitem("bitPrimary") = 1 then %>--%>
                           <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="../images/edit.png" CommandArgument='<%# Eval("ID")%>' CommandName="Edit" Text="" />
</itemtemplate>
Posted
Updated 9-Feb-15 3:07am
v4

Learn and adapt from the following sample:
XML
<head runat="server">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
    </script>
    <script>
        $(function () {
            $ddl = $("[id*=ddMovetoStore]");
            $ddl.val("No");

            $imgButtonCollection = $("[id*=ImageButton1]");

            $ddl.on("change", function () {
                var index = $ddl.index($(this));
                imgButton = document.getElementById($imgButtonCollection[index].id);
                $imgButton = $(imgButton);
                if ($(this).val() == 'Yes') {
                    $imgButton.hide();
                } else {
                    $imgButton.show();
                }
            });
            return false;
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
            <Columns>
                <asp:TemplateField HeaderText="Type">
                    <ItemTemplate>
                        <asp:DropDownList ID="ddMovetoStore" runat="server" AutoPostBack="false">
                            <asp:ListItem Value="No">No</asp:ListItem>
                            <asp:ListItem Value="Yes">Yes</asp:ListItem>
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Edit">
                    <ItemTemplate>
                        <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="http://dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-MVP-64.png"
                            CommandArgument='<%# Eval("ID")%>' CommandName="Edit" Text="" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
 
Share this answer
 
Comments
[no name] 9-Feb-15 15:02pm    
thank u
[no name] 9-Feb-15 15:20pm    
i have tried but its not working,,after storing the value in gridview edit button is still active,,in gridview if move to store is selected to yes then edit button should disappear,,i have a drop down;list move to store yes or no select.if yes is selected and save button is pressed it is saved in gridview but edit is still showing??if u get it any more help,thanku

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