How do I display a field in grid contents as a hyperlik

Discussion in 'ASP .Net' started by Martin.Coetsee, Dec 14, 2006.

  1. Fellow developers,
    I need to find out how to display one of the fields listed in m
    gridview as a hyperlink. The field displays the physical file path o
    for example a pdf file. I want my users to be able to click on th
    field(filepath) and the browser must open the file it points to.
    I am using VS2005, setup in web developer mode. The database behind i
    is MS-SQL 2005
    thanks in advance!

    MartinCoetse

    --
    Martin.Coetse
    -----------------------------------------------------------------------
    Martin.Coetsee's Profile: http://www.hightechtalks.com/m43
    View this thread: http://www.hightechtalks.com/t42680
    Martin.Coetsee, Dec 14, 2006
    #1
    1. Advertising

  2. Martin.Coetsee

    mark carew Guest

    On Thu, 14 Dec 2006 12:45:48 -0600, Martin.Coetsee wrote:

    > Fellow developers,
    > I need to find out how to display one of the fields listed in my
    > gridview as a hyperlink. The field displays the physical file path of
    > for example a pdf file. I want my users to be able to click on the
    > field(filepath) and the browser must open the file it points to.
    > I am using VS2005, setup in web developer mode. The database behind it
    > is MS-SQL 2005
    > thanks in advance!
    >
    > MartinCoetsee


    Hi Martin

    The gridView has an "onRowCommand" that you can assign a delegate to. The
    column could be a button whose "text" is the name of the pdf and whose
    commandName is say "pdfFinder". Below is a loose example cobbled together
    from another app (code is not tested!!). I build my columns dynamically in
    the other app.

    HTH
    Mark

    e.g.
    <asp:GridView ID="pdfGridView"
    runat="server"
    Style="z-index: 100; width: 650"
    onRowCommand="pdfRowCommand"
    BorderStyle="None"
    GridLines="None"
    ShowHeader="false"
    RowStyle-VerticalAlign="Top"
    RowStyle-Height="17px" >
    <Columns>
    <asp:TemplateField HeaderText="PDF File">
    <ItemTemplate>
    <asp:Button
    ID="pdfButton"
    runat="server"
    CommandName="pdfFinder"
    CommandArgument='<%# Eval("pdfFile") %>'
    Text='<%# Eval("pdfFile") %> />
    </ItemTemplate>
    </Columns>
    </asp:GridView>

    protected void pdfRowCommand(Object src, GridViewCommandEventArgs e)
    {
    string commandIs = e.CommandName;
    if (commandIs == "pdfFinder")
    {
    // get the row index stored in the CommandArgument property
    int index = Convert.ToInt32(e.CommandArgument);
    // get the GridViewRow where the command is raised
    GridViewRow selectedRow = ((GridView)e.CommandSource).Rows[index];
    // get the pdfName
    string pdfName = selectedRow.Cells[0].Text;
    // Show the pdf
    Session["PDFFileName"] = pdfName;
    Server.Transfer("showPdf.aspx");
    }
    mark carew, Dec 14, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page