Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hyperlink url for an asp.net gridview column

I have a gridview that returns values from a directory path such as :

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

How can I get the values under the "Name" column to have a url similar to "javascript:OpenSecure('abcd.doc') ?

Update: Given the HTML code below, I am unable to see the hyperlink in the Name field.

<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"/>

like image 280
Frank Avatar asked Feb 10 '26 22:02

Frank


2 Answers

Convert Name field to <ItemTemplate> and try adding a hyperlink

<asp:HyperLink ID="hplName" runat="server"  NavigateUrl='<%# "javascript:OpenSecure(''' + Eval("Name") ''') %>' Text='<%# Eval("Name") %>'/>
like image 178
Nalaka526 Avatar answered Feb 12 '26 14:02

Nalaka526


You would need a custom column for that:

http://msdn.microsoft.com/en-us/library/ms228046.aspx

like image 25
Burt Avatar answered Feb 12 '26 16:02

Burt