Results 1 to 6 of 6

Thread: Select a row in gridview without select button/link

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    320

    Select a row in gridview without select button/link

    I want to select a row of gridview and display a DetailsView. There is issue of real estate on page so I do not want to use a select button. Please advise how can we achieve this?
    Thanks

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,606

    Re: Select a row in gridview without select button/link

    I Will give you the opposite solution, figure out the one you want:
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: Select a row in gridview without select button/link

    I usually make one or more of the fields a hyperlink and use that as my select to drill into a details page, e.g. if I have a list of projects, I make the project name a link (or button or whatever you want, just a clickable control that handles your Select code). Then in your RowDataBound you can do something like the following to make the link:

    Code:
        Protected Sub MyGridView_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles MyGridView.RowDataBound
            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim MyLinkButton As LinkButton = e.Row.FindControl("MyLinkButton")
    
                MyLinkButton.PostBackUrl = "~\MyPage.aspx?ID=" & MyGridView.DataKeys(e.Row.RowIndex).Value
    Last edited by SeanGrebey; Nov 20th, 2012 at 11:09 PM.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  4. #4
    Hyperactive Member jasonwucinski's Avatar
    Join Date
    Mar 2010
    Location
    Pittsburgh
    Posts
    452

    Re: Select a row in gridview without select button/link

    You can just use the row itself as a link. When the user mouses over the row, change the color (this will help alert them that the row itself is interactive). Have each row a hidden control with a unique ID. When the user clicks the row, your codebehind can determine the row number. Use that row number to get the corresponding hidden control. Then, use the ID from the hidden control to process the request from there.
    if i was able to help, rate my post!

  5. #5
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,606

    Re: Select a row in gridview without select button/link

    It not mandatory but i think it would be better to get the gridview.Datakeys for determining the row.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  6. #6
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: Select a row in gridview without select button/link

    You can set the link/button commandArgument = datakey and use the grid.rowCommand event to get it. All these suggestions require viewstate on the grid if that's ok, I's the detailview is on the same page?
    The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width