Click here to Skip to main content
16,012,759 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi can anyone help me to get the value of gridview cell and assign it to the textbox and label using jquery code???

What I have tried:

$("#<%=GridView1.ClientID %> tr").each(function() {
//Skip first(header) row
if (!this.rowIndex) return;
var age = $(this).find("td:last").html();
list += age + "
";

i think this is the code for getting last column values
Posted
Updated 18-Oct-16 18:56pm
Comments
Aashish68 18-Oct-16 9:39am    
anyone help me
Richard Deeming 18-Oct-16 9:43am    
Try showing a little patience. Most of us have real jobs we need to do, which takes precedence over volunteering to answer questions on CodeProject.
Aashish68 18-Oct-16 9:51am    
sorry for the rush up,am really confused by searching for this.
Karthik_Mahalingam 19-Oct-16 0:09am    
it should happen automatically or on button click?
Aashish68 19-Oct-16 0:50am    
on button click

Try something like this:
JavaScript
var list = $("#<%=GridView1.ClientID %> tr:not(:first-of-type) td:last-of-type")
    .map(function(){ return this.innerHTML; })
    .get()
    .join("\n");

:not() Selector | jQuery API Documentation[^]
:first-of-type Selector | jQuery API Documentation[^]
:last-of-type Selector | jQuery API Documentation[^]
.map() | jQuery API Documentation[^]
 
Share this answer
 
JavaScript
<script type="text/javascript">
        $(function () {
            $("[id*=Button1]").live("click", function () {
                debugger;
                var row = $(this).closest('tr');
                var id = row.find("td:first").text();
                $("#<%=TextBox3.ClientID%>").val(id);
                var branch = row.find("td:nth-child(2)").text();
                $("#<%=TextBox4.ClientID%>").val(branch); 
}
 </script>


JavaScript
<asp:content id="Content2" contentplaceholderid="ContentPlaceHolder1" runat="server">
 <input type="button" id="Button1" value="EDIT" name="Button1" causesvalidation="false" CommandName=""/>
 <asp:textbox id="TextBox3" runat="server" style="margin-left: 130px"></asp:textbox>
 <asp:textbox id="TextBox4" runat="server" style="margin-left: 97px"></asp:textbox>
</asp:content>
 
Share this answer
 

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