GridView whole row select

P

p3t3r

In .NET 1.x it was possible to add an onclick callback to invoke the
selection of a row in the grid providing there was a Select command.

This still works in .NET 2.0 but now the cell with the Select command must
be visible. The users are accustomed to being able to select without seeing
an extra column.

If the Select command is not visible the page raise an error as the event is
invalid. How can I keep the Select command invisible and yet still use the
event?

Here's the code (VB) to put in the RowDataBound event for the grid

If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand';
this.style.backgroundColor='lightpink';")
e.Row.Attributes.Add("onmouseout",
"this.style.backgroundColor='';")
e.Row.Attributes.Add("onclick",
Page.ClientScript.GetPostBackEventReference(sender, "Select$" +
e.Row.RowIndex.ToString))
End If
 
P

Phillip Williams

Hello,

Your code would have worked just fine if you had used the display=none
attribute of CSS instead of setting the Visible attribute of the CommandField
to false, e.g.
<asp:CommandField SelectText ="Select" ShowSelectButton="true"
ItemStyle-CssClass ="HiddenColumn" />

and in your css add a definition like this:
.HiddenColumn{display:none;}
 
P

Phillip Williams

Don't forget to set the header style to the same css
<asp:CommandField SelectText ="Select" ShowSelectButton="true"
ItemStyle-CssClass = "HiddenColumn" HeaderStyle-CssClass ="HiddenColumn" />
 
P

p3t3r

Thanks Phillip. I like the simple solutions the best.

Maybe MS will either add this as an attribute to the column or change the
Visible attribute to mean this rather than its current meaning.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top