DataGrid problem - help!

Discussion in 'ASP .Net Web Controls' started by Bob H, Feb 25, 2004.

  1. Bob H

    Bob H Guest

    Hi,

    I'm new to ASP.Net and am having problems with clicking on a grid item and
    being forwarded to another page. Can anyone help out please?

    In my grid I've a template column to show a link comprised of several
    columns of data (only 1 shown here). I've tried a couple of ways: First I've
    tried using the OnCommand of the LinkButton and then I tried using the
    OnItemCommand of the Datagrid to point to my ViewDetails sub in the code
    behind file

    <asp:datagrid...>
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:LinkButton OnCommand="ViewDetails" Runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.Name")%>'></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid>

    Sub ViewDetails(ByVal sender As System.Object, ByVal e As CommandEventArgs)
    Response.Redirect("viewdetails.aspx", False)
    End Sub

    Once the user clicks the link, I thought that the Viewdetails sub gets
    called and they get forwarded to the viewdetails.aspx. This code only seems
    to postback to the same page ie the ViewDetails sub doesn't seem to get
    called (Once I've got this page working, the idea was to get the ID of the
    row the user clicked on and post it with the form to the viewdetails.aspx)

    Any clues/pointers please?

    Cheers

    Bob
    Bob H, Feb 25, 2004
    #1
    1. Advertising

  2. Bob H

    Bob H Guest

    ...should have set the EnableViewState for the datagrid to True and the
    OnItemCommand event gets fired.

    bob

    "Bob H" <> wrote in message
    news:c1i2ne$ov4$...
    > Hi,
    >
    > I'm new to ASP.Net and am having problems with clicking on a grid item and
    > being forwarded to another page. Can anyone help out please?
    >
    > In my grid I've a template column to show a link comprised of several
    > columns of data (only 1 shown here). I've tried a couple of ways: First

    I've
    > tried using the OnCommand of the LinkButton and then I tried using the
    > OnItemCommand of the Datagrid to point to my ViewDetails sub in the code
    > behind file
    >
    > <asp:datagrid...>
    > <Columns>
    > <asp:TemplateColumn>
    > <ItemTemplate>
    > <asp:LinkButton OnCommand="ViewDetails" Runat="server" Text='<%#
    > DataBinder.Eval(Container, "DataItem.Name")%>'></asp:LinkButton>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    > </Columns>
    > </asp:datagrid>
    >
    > Sub ViewDetails(ByVal sender As System.Object, ByVal e As

    CommandEventArgs)
    > Response.Redirect("viewdetails.aspx", False)
    > End Sub
    >
    > Once the user clicks the link, I thought that the Viewdetails sub gets
    > called and they get forwarded to the viewdetails.aspx. This code only

    seems
    > to postback to the same page ie the ViewDetails sub doesn't seem to get
    > called (Once I've got this page working, the idea was to get the ID of the
    > row the user clicked on and post it with the form to the viewdetails.aspx)
    >
    > Any clues/pointers please?
    >
    > Cheers
    >
    > Bob
    >
    >
    Bob H, Feb 25, 2004
    #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. sajvargs
    Replies:
    0
    Views:
    373
    sajvargs
    Feb 20, 2005
  2. Andreas Klemt
    Replies:
    0
    Views:
    267
    Andreas Klemt
    Oct 8, 2003
  3. roberto
    Replies:
    1
    Views:
    213
    roberto
    Feb 17, 2005
  4. John Walsch
    Replies:
    0
    Views:
    189
    John Walsch
    Jul 9, 2004
  5. Eric
    Replies:
    1
    Views:
    180
    Steve Goodyear
    May 21, 2005
Loading...

Share This Page