views:

3963

answers:

4

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?

+1  A: 

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>
Eoin Campbell
A: 

ya this is correct but u didn't got my point,actually i hv to display data in gridview like Serial no/pdffile path/unit 1 /abc.pdf /7 2 /def.pdf /10 3 /ghi.pdf /11
ok & now i want a hyper link in this gridview,when i click 1st hyperlink button then 1st pdf file will be open in next page. if i select 2nd then 2nd pdf file will open.

plz reply me on below mail id

[email protected]

A: 

ya this is correct but u didn't got my point,actually i hv to display data in gridview like Serial no/pdffile path/unit 1 /abc.pdf /7 2 /def.pdf /10 3 /ghi.pdf /11 ok & now i want a hyper link in this gridview,when i click 1st hyperlink button then 1st pdf file will be open in next page. if i select 2nd then 2nd pdf file will open.

plz reply me on below mail id

[email protected]

A: 

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