want to open pdf file when a user clicks on hyperlink shown in gridview column.The name of the file is taken from first column of the gridview where file titles are stored.
hovering over hyperlink in gridview shows file link, but when clicked it doesnot open pdf file,
protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink hlink = (HyperLink)e.Row.FindControl("HL");
string url = "~/Docs/" + e.Row.Cells[1].Text +".pdf";
hlink.NavigateUrl = url;
hlink.Text = "Read";
}
}
The following error comes when hyperlink is clicked, as it is not able to open pdf file.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable
which event is called when hyperlink is clicked in a gridview, maybe pdf application is to be opened there. Please suggest. Thanks in adavance.
The error suggests that your file doesn’t exist. What you should do is to forego the concatenation that you do and instead include the whole name of the file (including extension) in your data source and use it (or even the entire path). The reason you want to do it that way is because you may have modified/formatted/encoded the cell text strictly for aesthetic purposes. You could have even added some embedded html to style it.
I would imagine it would look something like this: