简体   繁体   English

为ASP.NET超链接字段传递SQL表参数

[英]Passing SQL table parameters for ASP.NET hyperlink field

I have an asp:gridview populated with SQL (MSSQL 2008) data. 我有一个用SQL(MSSQL 2008)数据填充的asp:gridview。 The cells have naivgateurl fields so I can redirect users to a special page with some charts. 单元格具有naivgateurl字段,因此我可以将用户重定向到带有某些图表的特殊页面。 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. 因此,基本上,我希望URL转到〜\\ charts \\ load.aspx?ID = 1,其中1是数据库中该车的ID号。 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#. 我的页面使用C#。 Thanks for any assistance! 感谢您的协助!

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 将DataField值更改为数据源中返回的实际列名
  • In the HyperLinkField, ensure that you've updated both the DataNavigateUrlFields value and the DataTextField value with appropriate column names from your datas ource 在HyperLinkField中,确保已使用数据中的适当列名更新了DataNavigateUrlFields值和DataTextField值。

I hope this is what you're looking for. 我希望这是您要寻找的。

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM