Click here to Skip to main content
12,954,522 members (56,981 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 11 Jul 2006

Adding click event to rows in a DataGrid

, 16 Jul 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
A simple way to select a DataGrid row by clicking it.


I spent some time trying to find a way to simulate FullRowSelect on a DataGrid, and couldn't really see any obvious way of doing it (all the solutions I tried were pretty complicated, and crashed half of the time), but after a while, it hit me that you could use JavaScript. All you need to do is:

protected void nameOfGridView View_RowDataBound(object sender, GridViewRowEventArgs e)
    if (e.Row.RowType == DataControlRowType.DataRow)
        e.Row.Attributes.Add("onmouseover", "'hand'");
        e.Row.Attributes.Add("onclick", "javascript:__doPostBack" +
           "('nameOfGridView '"
           + ", 'Select$" + e.Row.RowIndex + "')");

Just add this method to the RowDataBound Delegate for your DataGrid, and replace nameOfGridView with the name of your GridView. That's all, easy!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralPrettyDataGrid by Scott Mitchell Pin
MeDeeSa15-Dec-06 10:45
memberMeDeeSa15-Dec-06 10:45 
GeneralRe: PrettyDataGrid by Scott Mitchell Pin
ssjvackar16-Dec-06 10:59
memberssjvackar16-Dec-06 10:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 16 Jul 2006
Article Copyright 2006 by ssjvackar
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid