all groups > asp.net webcontrols > november 2005 >
You're in the

asp.net webcontrols

group:

GridView whole row select


GridView whole row select p3t3r
11/29/2005 6:09:03 PM
asp.net webcontrols: 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

RE: GridView whole row select Phillip Williams
11/29/2005 7:29:02 PM
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;}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


[quoted text, click to view]
RE: GridView whole row select Phillip Williams
11/29/2005 8:19:05 PM
Don't forget to set the header style to the same css
<asp:CommandField SelectText ="Select" ShowSelectButton="true"
ItemStyle-CssClass = "HiddenColumn" HeaderStyle-CssClass ="HiddenColumn" />
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


[quoted text, click to view]
RE: GridView whole row select p3t3r
11/30/2005 10:21:10 AM
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.

[quoted text, click to view]
Re: GridView whole row select SugarDaddy
4/3/2006 1:47:10 PM

[quoted text, click to view]

I actually wanted to accomplish the same thing. I just posted a
solution here:
[url]http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/6e29b371de01b72f?hl=en[/url]

Basically, use ClientScriptManager's GetPostBackEventReference to
generate the __doPostBack call, passing it "Select$"+[RowIndex] for the
onclick handler for each row. Hope this helps.



--
SugarDaddy
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------
AddThis Social Bookmark Button