Trido
Trido

Reputation: 545

Passing SQL table parameters for ASP.NET hyperlink field

I have an asp:gridview populated with SQL (MSSQL 2008) data. The cells have naivgateurl fields so I can redirect users to a special page with some charts. Since there are multiple vehicles displayed in the table, I want users to get specific info on each vehicle when they click that specific row. So basically, I want the URL to go to ~\charts\load.aspx?ID=1 where 1 is the ID number of that car in the database. Can anyone point me in the right direction? I have seen some examples, but they are not related enough to my requirements for me to figure it out. My page uses C#. Thanks for any assistance!

Upvotes: 0

Views: 827

Answers (1)

Rastus7
Rastus7

Reputation: 416

You could try something like this:

<asp:GridView ID="oGridView" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="oObjectDataSource" AutoGenerateColumns="False" Width="100%" CellPadding="3" PageSize="50" GridLines="None">
    <Columns>
        <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" HeaderStyle-HorizontalAlign="Left" ReadOnly="true" />
        <asp:HyperLinkField DataNavigateUrlFields="CarID" DataNavigateUrlFormatString="/charts/load.aspx?ID={0}" DataTextField="CarName" HeaderText="CarName" SortExpression="CarName" HeaderStyle-HorizontalAlign="Left" />
    </Columns>
    <PagerSettings Mode="NumericFirstLast" Position="TopAndBottom" />
</asp:GridView>

You'll need to:

  • Change the DataField values to actual column names being returned in your data source
  • In the HyperLinkField, ensure that you've updated both the DataNavigateUrlFields value and the DataTextField value with appropriate column names from your datas ource

I hope this is what you're looking for.

Cheers!

Upvotes: 1

Related Questions