advancing with the asp:datagrid

Discussion in 'ASP .Net' started by Tim Smith, Nov 25, 2003.

  1. Tim Smith

    Tim Smith Guest

    In my .cs code I populate set the DataSource appropriately and I can
    get my DataGrid to appear, though sorting throws an error
    'dgDataGrid1__ctl1__ctl0' of type 'DataGridLinkButton' must be placed
    inside a form tag

    But ignoring that, with my asp:DataGrid how can I have a column of
    values each with a link e.g.

    <a href="Details.aspx?id=" + MY_NBR>MY_NBR</a>


    <asp:DataGrid id="ReportHeader" runat="server" AllowSorting="True"
    AutoGenerateColumns="False" >
    <Columns>
    <asp:BoundColumn DataField="MY_GROUP"
    HeaderText="Report Group" SortExpression="MY_GROUP">
    </asp:BoundColumn>
    <asp:BoundColumn DataField="MY_NAME"
    HeaderText="Report Name" SortExpression="MY_NAME">
    </asp:BoundColumn>
    <asp:BoundColumn DataField="MY_NBR"
    HeaderText="Report Nbr" DataFormatString="{0:d}"
    SortExpression="MY_NBR">
    </asp:BoundColumn>
    </Columns>
    </asp:DataGrid>

    thanks!
     
    Tim Smith, Nov 25, 2003
    #1
    1. Advertising

  2. That's what the HyperLinkColumn is for. You set the field that you pull for
    the URL (in this case, MY_NBR), then set the format string, and then the {0}
    portion will substitute in the field from the database. The DataTextField
    property then shows what to display, and if you want to decorate this
    somehow just use the DataTextFormatString property.

    eg:

    <asp:HyperLinkColumn HeaderText="Report Nbr" DataNavigateUrlField="MY_NBR"
    DataNavigateUrlFormatString="details.aspx?id={0}" DataTextField="MY_NBR" />


    --
    Chris Jackson
    Software Engineer
    Microsoft MVP - Windows Client
    Windows XP Associate Expert
    --
    More people read the newsgroups than read my email.
    Reply to the newsgroup for a faster response.
    (Control-G using Outlook Express)
    --

    "Tim Smith" <> wrote in message
    news:...
    > In my .cs code I populate set the DataSource appropriately and I can
    > get my DataGrid to appear, though sorting throws an error
    > 'dgDataGrid1__ctl1__ctl0' of type 'DataGridLinkButton' must be placed
    > inside a form tag
    >
    > But ignoring that, with my asp:DataGrid how can I have a column of
    > values each with a link e.g.
    >
    > <a href="Details.aspx?id=" + MY_NBR>MY_NBR</a>
    >
    >
    > <asp:DataGrid id="ReportHeader" runat="server" AllowSorting="True"
    > AutoGenerateColumns="False" >
    > <Columns>
    > <asp:BoundColumn DataField="MY_GROUP"
    > HeaderText="Report Group" SortExpression="MY_GROUP">
    > </asp:BoundColumn>
    > <asp:BoundColumn DataField="MY_NAME"
    > HeaderText="Report Name" SortExpression="MY_NAME">
    > </asp:BoundColumn>
    > <asp:BoundColumn DataField="MY_NBR"
    > HeaderText="Report Nbr" DataFormatString="{0:d}"
    > SortExpression="MY_NBR">
    > </asp:BoundColumn>
    > </Columns>
    > </asp:DataGrid>
    >
    > thanks!
     
    Chris Jackson, Nov 25, 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. Replies:
    17
    Views:
    793
  2. Johannes Schaub (litb)

    Advancing past the last element of an array

    Johannes Schaub (litb), Dec 27, 2009, in forum: C Programming
    Replies:
    10
    Views:
    622
    Tim Rentsch
    Jan 13, 2010
  3. David A. Black
    Replies:
    0
    Views:
    93
    David A. Black
    Sep 13, 2007
  4. Peter Marks

    Trouble advancing date in iterator

    Peter Marks, Nov 27, 2007, in forum: Ruby
    Replies:
    2
    Views:
    95
    Peter Marks
    Nov 28, 2007
  5. David A. Black
    Replies:
    0
    Views:
    107
    David A. Black
    Jun 7, 2008
Loading...

Share This Page