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

M

Martin.Coetsee

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
 
M

mark carew

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");
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top