welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Friday, June 1, 2012

How to get the selected row value in gridview using javascript?

In this article about to pick the selected row data from gridview using javascript.

Inside gridview i added one html checkbox, when the user select any  checkbox ,on click event we call the javascript and show the selected column value using alert, it’s very simple process. on click event we pass the row item index, by using row index we can easily get selected  any row column values.
By getting column values using rowindex can achieve only if we use Bound field in gridview..

   <script type="text/javascript">
        function chng(t, obj) {
            if (obj.checked == true) {
                var CellValue, cell, tj;
                var table = document.getElementById('<%=GridView1.ClientID %>');
                cell = document.getElementById('<%=GridView1.ClientID %>').rows[parseInt(t) + 1].cells[1];
                tj = cell.innerHTML;


<asp:GridView ID="GridView1" AutoGenerateColumns="False" AutoGenerateSelectButton="false"
        AllowPaging="True" SelectedIndex="1" AllowSorting="true"
                    <input type="checkbox" value="getIndex" onclick="chng(<%# Container.DataItemIndex %>,this);" />
            <asp:BoundField DataField="Name" HeaderText="Name" InsertVisible="False" ReadOnly="True"
                SortExpression="Name" />
            <asp:BoundField DataField="roll" HeaderText="Address" SortExpression="Address" />
        <SelectedRowStyle BackColor="LightCyan" ForeColor="DarkBlue" Font-Bold="true" />

Above code works perfectly, In an alert window its show the selected value from the grid view..
I hope it’s helpful…keep reading


Post a Comment