|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
GridView whole row selectselection 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 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;} Show quoteHide quote "p3t3r" wrote: > 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 > > Don't forget to set the header style to the same css
<asp:CommandField SelectText ="Select" ShowSelectButton="true" ItemStyle-CssClass = "HiddenColumn" HeaderStyle-CssClass ="HiddenColumn" /> Show quoteHide quote "Phillip Williams" wrote: > 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 > > > "p3t3r" wrote: > > > 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 > > > > 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. Show quoteHide quote "Phillip Williams" wrote: > 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 > > > "Phillip Williams" wrote: > > > 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 > > > > > > "p3t3r" wrote: > > > > > 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 > > > > > > p3t3r wrote:
> *In .NET 1.x it was possible to add an onclick callback to invoke
> the I actually wanted to accomplish the same thing. I just posted a
solution here:> 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? > .... * [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 ------------------------------------------------------------------------
Validators in composite control firing prematurely
VS2005 C# is very BUGGY, please hlp BoundField and DataFormatString in ASP.NET 2.0 - Bug ? Problem with Custom Web Controls in Visual Studio 2005 datagrid pixel height not respected How to cycle through checkboxes in a datagrid and find out which ones are checked? ReadOnly (HTML) controls to stay black and not grey repost: custom control client values gone with postback -- no solution found... Help on rendering a control from page ??? Dynamic user control Event Handling (VS.NET Ent 2003) |
|||||||||||||||||||||||