网格视图中的超链接列
本文关键字:超链接 视图 网格 | 更新日期: 2023-09-27 17:57:05
我在 GridView FirstName
和 LastName
中有 2 列。我希望名字列中的所有行都在超链接中。我试过这个但没有用。我该怎么做?
解析器错误
Parser Error Message: Databinding expressions are only supported on objects
that have a DataBinding event. System.Web.UI.WebControls.HyperLinkField does not
have a DataBinding event.
法典:
<asp:GridView ID="CustomersGridView" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:HyperLinkField Text='<%# Eval("FirstName") %>' />
</Columns>
</asp:GridView>
试试这个。
<asp:HyperLinkField
DataTextField="FirstName"
HeaderText="First Name"
SortExpression="FirstName"
DataNavigateUrlFields="FirstNameID"
DataNavigateUrlFormatString="PersonDetails.aspx?FirstNameID={0}" /> //use if you want to nevigate to other page
尝试使用 DataTextField
属性:
<asp:HyperLinkField DataTextField="FirstName" />
您需要
将其转换为模板字段:
<asp:GridView ID="CustomersGridView" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
<asp:itemtemplate>
<asp:HyperLinkField Text='<%# Eval("FirstName") %>' />
...