Datagrid - need to detemine index of datarow on hyperlink click

Discussion in 'ASP .Net Web Controls' started by debiken, Nov 17, 2003.

  1. debiken

    debiken Guest

    I have an aspx page that loads a datagrid from a fairly
    complex query. It grabs lots of order information but I
    only display part of it on this "order summary" page. The
    order number is a hyperlinkcolumn which opens a new
    window, and that page displays much more order detail (but
    from the same datatable as the original datagrid is bound
    to...trying to save another trip to the DB). I am caching
    the datatable, and want to populate the detail window with
    that data, but don't know the table row. I can't get an
    event to fire, onItemCommand never takes off on a
    hyperlink, even if I use a TemplateColumn with an anchor
    tag in the ItemTemplate and bind the data using the
    container.DataItem method. Anyone know of a way to get
    this table row on a hyperlink click? (I have tried using
    the Container.DataItem as well, and can't get the row
    index out of it...). Any help or ideas are greatly
    appreciated!
     
    debiken, Nov 17, 2003
    #1
    1. Advertising

  2. Hi,

    You wrote that you need the row index. Usually, most folks just need the
    key field. In any case, the grid's ItemDataBound event should do what you
    want. Here's a sample snippet. In this sample I add a new link control. You
    could instead have a link in the template and use FindControl to get a
    reference to it. Then you could change its NavigateURL. In this sample, I
    create a NavigateUrl using data from the database and the data grid's item
    number for the row.

    Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs) Handles
    DataGrid1.ItemDataBound
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
    ListItemType.AlternatingItem Then
    Dim h As New HyperLink
    h.NavigateUrl = "http:/" & e.Item.DataItem("au_lname") &
    ".aspx?a=" & e.Item.ItemIndex
    h.Text = e.Item.DataItem("au_lname")
    e.Item.Cells(0).Controls.Add(h)
    End If
    End Sub


    Thank you, Mike
    Microsoft, ASP.NET Support Professional

    Microsoft highly recommends to all of our customers that they visit the
    http://www.microsoft.com/protect site and perform the three straightforward
    steps listed to improve your computer’s security.

    This posting is provided "AS IS", with no warranties, and confers no rights.


    --------------------
    > Content-Class: urn:content-classes:message
    > From: "debiken" <>
    > Sender: "debiken" <>
    > Subject: Datagrid - need to detemine index of datarow on hyperlink click
    > Date: Mon, 17 Nov 2003 14:19:25 -0800
    > Lines: 17
    > Message-ID: <054601c3ad58$dc21b630$>
    > MIME-Version: 1.0
    > Content-Type: text/plain;
    > charset="iso-8859-1"
    > Content-Transfer-Encoding: 7bit
    > X-Newsreader: Microsoft CDO for Windows 2000
    > Thread-Index: AcOtWNwhpwc6d/tNT3ipe/8p3TH/4A==
    > X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > Path: cpmsftngxa06.phx.gbl
    > Xref: cpmsftngxa06.phx.gbl

    microsoft.public.dotnet.framework.aspnet.webcontrols:16236
    > NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
    > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    >
    > I have an aspx page that loads a datagrid from a fairly
    > complex query. It grabs lots of order information but I
    > only display part of it on this "order summary" page. The
    > order number is a hyperlinkcolumn which opens a new
    > window, and that page displays much more order detail (but
    > from the same datatable as the original datagrid is bound
    > to...trying to save another trip to the DB). I am caching
    > the datatable, and want to populate the detail window with
    > that data, but don't know the table row. I can't get an
    > event to fire, onItemCommand never takes off on a
    > hyperlink, even if I use a TemplateColumn with an anchor
    > tag in the ItemTemplate and bind the data using the
    > container.DataItem method. Anyone know of a way to get
    > this table row on a hyperlink click? (I have tried using
    > the Container.DataItem as well, and can't get the row
    > index out of it...). Any help or ideas are greatly
    > appreciated!
    >
     
    Mike Moore [MSFT], Nov 18, 2003
    #2
    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. Doug
    Replies:
    0
    Views:
    881
  2. TB
    Replies:
    8
    Views:
    73,233
    allAboutMe
    Jun 28, 2012
  3. debiken
    Replies:
    0
    Views:
    266
    debiken
    Nov 17, 2003
  4. HelpPlease

    Datarow can't bind to datagrid...I need a workaround

    HelpPlease, Feb 11, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    731
    Marshal Antony
    Feb 12, 2004
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    315
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page