How do get the data of the selected row in a datagridusing javascript.

amukta used Ask the Experts™
I have a datagrid.

I have a link button for one of the columns.
When I click on the linkbutton, I should be able to get the data of the selected row.

Any code/logic is greatly appreciated.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Here's a sample of what you are asking about (see snippet). By simply attaching a JS event to your linkbutton and passing the 'this' keyword you can use that reference to easily get the row the linkbutton resides in, and then the individual data.
<html xmlns="">
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
		function getRowData(lbtn)
			var row = lbtn.parentNode.parentNode; //refers to row
			alert(row.cells[1].innerHTML + ' / ' + row.cells[2].innerHTML);
    <form id="form1" runat="server">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
                     <asp:CheckBox runat="server" ID="chkSelected"/>
               <asp:BoundField DataField="testid" HeaderText="ID" />
               <asp:BoundField DataField="fName" HeaderText="First Name" />
					<asp:LinkButton ID="lnkBtn" runat="server" Text="ClickMe" OnClientClick="getRowData(this);return false;" />
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
        <span>Checked Row Values Here: </span>
        <asp:TextBox ID="txtResults" runat="server" />

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial