Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
i have hidden field value inside a grid view i bound it with a linq query i want to get selected field value through asp:link button my asp.net code is :


<pre lang="c#"><asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="EditCol">EDIT</asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
 <asp:TemplateField>
                            <ItemTemplate>
                                <input id="Hidden1" runat="server" type="hidden" visible="true" class="H" value='<%# Bind("MBody") %>' />
                            </ItemTemplate>
                        </asp:TemplateField>


when i want to get selected row value using this jquery code :

JavaScript
$(document).on("click", "[id*=EditButton]", function (event) {
            event.preventDefault();
            var body = $("[id*=Hidden1]").val();
alert(body);
}


it just exhibits the first bounding field value not selected value could you please help me to overcome this issue ?
Posted

1 solution

You are working with templates, so your ids are never will be presented in the grid, otherwise you should end up with numerous elements with the same id. Think about a data set with 10 rows! In every row there is a hidden field, but their ids must be different!
You may use a class based jQuery selector:
JavaScript
$("input.H")
 
Share this answer
 
Comments
Mahdi Ghafoorian 12-May-14 9:26am    
i did use class base too , but unfortunately it was just the same !!

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