Abhishek
Abhishek

Reputation:

how can i use Hyperlink button in gridview?

How can I use Hyperlink button in gridview. I mean when I run my program,all data is displayed in gridview,but I want hyperlink in gridview, so that when I will click in hyperlink it will show the select path which is in gridview : if there is pdf file path and I just click on this hyper link then I can see the pdf file.

Can you tell me how can I do this?

Upvotes: 0

Views: 7462

Answers (2)

zip
zip

Reputation:

Here is what i would do

" SelectCommand="SELECT * FROM [Customers]">

Then for the test.aspx page i would have a datasource like this

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:BlissConnectionString %>" 
    SelectCommand="SELECT * FROM [Customers] WHERE CustomerID = @ID">
    <SelectParameters>
        <asp:QueryStringParameter Name="ID" QueryStringField="ID" />
    </SelectParameters>
</asp:SqlDataSource>
<br />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
    DataKeyNames="CustomerID" DataSourceID="SqlDataSource1" Height="50px" 
    Width="125px">
    <Fields>
        <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" 
            InsertVisible="False" ReadOnly="True" SortExpression="CustomerID" />
        <asp:BoundField DataField="CustomerName" HeaderText="CustomerName" 
            SortExpression="CustomerName" />
        <asp:BoundField DataField="CustomerAddress" HeaderText="CustomerAddress" 
            SortExpression="CustomerAddress" />
        <asp:BoundField DataField="CustomerPhone" HeaderText="CustomerPhone" 
            SortExpression="CustomerPhone" />
        <asp:BoundField DataField="CustomerEmail" HeaderText="CustomerEmail" 
            SortExpression="CustomerEmail" />
    </Fields>
</asp:DetailsView>

Totally untested but hope this helps you.

Regards

Liam

Upvotes: 0

Eoin Campbell
Eoin Campbell

Reputation: 44268

You need to use a template field. e.g. lets say you're column is called 'PdfUrl'

Then add a column to your datagrid. that looks like

<asp:TemplateField HeaderText="Link" SortExpression="PdfUrl">
    <itemtemplate>
        <asp:HyperLink runat="server" ID="hlkPDF" NavigateURL='<%# DataBinder.Eval(Container.DataItem, "PdfUrl") %>' />
    </itemtemplate>
</asp:TemplateField>  

Upvotes: 1

Related Questions