Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My gridview has autogeneratecolumns = true and I want to get the specific column index value of where the user click on the gridview cell. If the user clicks on the cell of third row, fifth column, then it will show the Header text of Third Row & Fifth Column. How can I get the specific column index value. Please help me out.

C#
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    Label1.Text = "RowHeader - " + GridView1.SelectedRow.Cells[0].Text + " and ColumnHeader - " + GridView1.HeaderRow.Cells[0].Text;
}
Posted
Comments
So, what is the problem with this code?
Arunachalam Gurusamy 4-Nov-13 3:45am    
GridView1.HeaderRow.Cells[0].Text - It will display the first column header text only. But I want to display the column header where the user clicks on the cell...

1 solution

Finally I did this using the below jQuery...

XML
<script type="text/javascript">
    $(document).ready(function () {
        $('#GridView1>tbody>tr>td').click(function () {
            var col = $(this).parent().children().index($(this));
            var title = $(this).closest("table").find("th").eq(col).text();
            $('p').html("Cell Clicked Text ---> " + $(this).text() + "<br/>" + "Column Name  ---> " + title + "<br/>" + " Column Index ---> " + col + "<br/>");
        });
    });
</script>
 
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