Search code examples
asp.netvb.netgridview.net-2.0grid

Selecting a rows in the standard .net 2.0 GridView Using VB.net & JavaScript


Does anyone know how i can get the grid to select a row by clicking on any cell in the row?

The only way i can do this at the moment is by setting the AutoGenerateSelectButton property to True, but this adds a column to the grid with a crude "select" hyperlink and only selects the row if the word "Select" is cliked on.

Surely there has to be a better way!?!?

NOTE - I do not use C#


Solution

  • You need to add some javascript to the row in RowDataBound

       e.Row.Attributes["onclick"] = 
                        ClientScript.GetPostBackClientHyperlink
                            (this.GridView1, "Select$" + e.Row.RowIndex);
    

    There's a CodeProject article about it here, which goes into much more detail.