1

我在 GridViewFirstNameLastName. 我希望 FirstName 列中的所有行都位于超链接中。我已经尝试过了,但没有奏效。我该怎么做 ?

解析器错误

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>
4

3 回答 3

3

试试这个..

<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
于 2013-01-31T18:31:31.347 回答
1

尝试使用该DataTextField属性

<asp:HyperLinkField DataTextField="FirstName" />
于 2013-01-31T18:24:50.307 回答
1

您需要将其转换为模板字段:

<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") %>' />
    ...
于 2013-01-31T18:25:26.810 回答