c# - GridView 中的超链接列

标签 c# asp.net gridview hyperlink

我在 GridView FirstNameLastName 中有 2 列。我希望 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>

最佳答案

试试这个..

<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

关于c# - GridView 中的超链接列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14632548/

相关文章:

c# - 根据 GET 请求为 ASP.NET MVC 自定义模型绑定(bind)器

asp.net - 如何使用 jQuery 和 AJAX 刷新 ASP.NET ListView?

javascript - 从按钮调用 javascript 函数会在我的 ASP.net 中隐藏 FullCalendar

asp.net - 为什么子控件在它们的容器之前初始化?

c# - Debug.Assert 似乎不适用于 Mono

c# - 迭代器变量是否有单数形式与复数形式相同的命名准则?

android - Android 中的 GridView ListSelector 重点?

c# - 运行大型 SQL 语句并填充 gridview

c# - 无法加载文件或程序集 'System.Web.Extensions'

c# - 在 C# 中创建文件 (.htm)