【问题标题】:Hyperlink url for an asp.net gridview columnasp.net gridview 列的超链接 url
【发布时间】:2011-12-05 04:50:28
【问题描述】:

我有一个从目录路径返回值的网格视图,例如:

            <table width="40%" border="0" style="margin-left:auto; margin-right:auto;">
                <tr>
                    <td align="center">
                        <asp:GridView ID="gvFileList" runat="server" AutoGenerateColumns="false" AllowSorting="true">
                            <columns>
                              <asp:boundfield datafield="Name" headertext="File Name"/>
                              <asp:boundfield datafield="Extension" headertext="File Type"/>
                              <asp:boundfield datafield="Length" headertext="Length"/>
                              <asp:boundfield datafield="LastCreateTime" headertext="Date"/>
                            </columns>
                        </asp:GridView>
                    </td>
                </tr>
            </table>

如何让“名称”列下的值具有类似于"javascript:OpenSecure('abcd.doc') 的网址?

更新: 鉴于下面的 HTML 代码,我无法在名称字段中看到超链接。

<asp:GridView ID="gvInvoiceList" runat="server" AutoGenerateColumns="false" AllowSorting="true">
                                <columns>
                                    <asp:TemplateField HeaderText="Name">
                                        <ItemTemplate><asp:Hyperlink ID="acctInvoiceRpt" NavigateUrl='<%# SetNavigateUrl(Eval("Name")) %>' runat="server"></asp:Hyperlink><%#Eval("Name")%></ItemTemplate>
                                    </asp:TemplateField>
                                  <asp:boundfield datafield="Extension" headertext="File Type"/>

【问题讨论】:

  • 将显示文本放在超链接的结束标记之前。 :Hyperlink>,或者使用Text属性...

标签: asp.net vb.net gridview


【解决方案1】:

将名称字段转换为&lt;ItemTemplate&gt; 并尝试添加超链接

<asp:HyperLink ID="hplName" runat="server"  NavigateUrl='<%# "javascript:OpenSecure(''' + Eval("Name") ''') %>' Text='<%# Eval("Name") %>'/>

【讨论】:

  • 查看我更新的代码。我在名称字段中看不到超链接;
【解决方案2】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多