Results 1 to 7 of 7

Thread: Gridview select

  1. #1

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    784

    Gridview select

    I have a web page with a Gridview control and I wish to select one of the rows without using a button or select column.
    I have tried the following two events, but none of them work. The Gridview does not know that it must select a row - or - nothing happens when I click the row:

    Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged
    Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs)

    Any help will be appreciated,
    Thanks
    PK

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Gridview select

    Hi,

    You may use JavaScript/jQuery to achieve that.

    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Gridview select

    Hi,

    You may use JavaScript/jQuery to achieve that.

    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  4. #4

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    784

    Re: Gridview select

    Thanks, but I have no idea how to write Java. Sorry.

  5. #5
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Gridview select

    Java is different from JavaScript/jQuery. JavaScript/jQuery interacts with ASP.NET in the client/browser side.

    Another option below is to add a javascript onclick to a gridview row on render event. But still, i prefer writing scripts on the front-end side.

    Code:
    protected override void Render(HtmlTextWriter writer)
        {
          foreach (GridViewRow r in GridViewEmployees.Rows)
          {
            if (r.RowType == DataControlRowType.DataRow)
            {
              r.Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridViewEmployees, "Select$" + r.RowIndex,true);
            }
          }
    
          base.Render(writer);
        }
    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  6. #6

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    784

    Re: Gridview select

    Hi KGComputers,
    I appreciate your help.
    However, the code you have given, I think, is in C#.
    I need to combine two fields of ACCESS in one column of my Gridview in code behind - combining the 'article name' with the 'URL link' anchor.
    Thanks
    PK

  7. #7
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Gridview select

    Yeah, I've not written ASP.NET Webforms using VB.NET for years now. Most of the web projects that I'm involved with are in C#. However, the logic I've given can be converted to VB.NET if you want to.

    Code:
    I need to combine two fields of ACCESS in one column of my Gridview in code behind - combining the 'article name' with the 'URL link' anchor.
    If this is another question, you may want to ask this in a separate thread.

    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

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