GridView whole row select

Discussion in 'ASP .Net Web Controls' started by p3t3r, Nov 30, 2005.

  1. p3t3r

    p3t3r Guest

    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, Nov 30, 2005
    #1
    1. Advertising

  2. 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
    >
    >
     
    Phillip Williams, Nov 30, 2005
    #2
    1. Advertising

  3. 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
    > >
    > >
     
    Phillip Williams, Nov 30, 2005
    #3
  4. p3t3r

    p3t3r Guest

    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.

    "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, Nov 30, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fernando Lopes
    Replies:
    0
    Views:
    3,196
    Fernando Lopes
    Apr 28, 2005
  2. =?Utf-8?B?RGFiYmxlcg==?=

    select gridview row without using select button?

    =?Utf-8?B?RGFiYmxlcg==?=, Mar 3, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    101,539
    dch31969
    Feb 27, 2009
  3. H5N1
    Replies:
    0
    Views:
    2,723
  4. news.microsoft.com

    Underline a whole row for a particular row

    news.microsoft.com, Mar 4, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    5
    Views:
    203
    Eliyahu Goldin
    Mar 6, 2005
  5. dhj

    How to hightlight whole row when select datagrid

    dhj, Jul 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    105
    Phillip Williams
    Jul 21, 2006
Loading...

Share This Page