Click here to Skip to main content
11,813,557 members (46,893 online)
Rate this: bad
Please Sign up or sign in to vote.
Select   Result.No                  URL 
Select     2   C:\Users\FABS\Documents\Xml Search\upload\count.xml
Select     3   C:\Users\FABS\Documents\Xml Search\upload\Doc.xml

My Gridview Showing like this ......then in URL column bind as link button in gridview
....Now problem is how to open or how to show that document when i click this URL link in gridview table....Pls help me????
Posted 28-Jan-13 0:15am
Edited 28-Jan-13 0:16am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Deenuji at 28-Jan-13 6:25am
Actually i have doubt on this?
Sushil Mate at 28-Jan-13 6:26am
what is that doubt?
Deenuji at 28-Jan-13 6:28am
i have url on this link but when i click this link i want to open or view that clicked xml document?
Sushil Mate at 28-Jan-13 6:30am
you will, you don't have to worry about it. windows has the association between .xml to internet explorer so whenever user clicks on that link it will open that XML document in IE.
Deenuji at 28-Jan-13 6:32am
s but how to select that particular link and redirect to open???
Sushil Mate at 28-Jan-13 6:36am
just follow the my solution & it will do the rest
Deenuji at 28-Jan-13 7:35am
so getting error only
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

If you want to open the file normally then you can use Response.Redirect(YourFilePath). And if you want to download the file then you can use the function below. Call the function in your RowCommand Event of GridView and pass the path of corresponding file. Try this:
<!--This should be there in your aspx file inside gridview itemtemplate-->
<asp:LinkButton ID="lnkView" runat="server" Text="View Document" CommandName="View" CommandArgument='<%#EVal("URL")%>'/>
protected void Gridview_RowCommand(Object sender, GridViewCommandEventArgs e)
   if(e.CommandName == "View")
public void DownloadFile(string FilePath)
    Response.ContentType = @"application\octet-stream";
    System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(FilePath));
    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
    Response.AddHeader("Content-Length", file.Length.ToString());
    Response.ContentType = "application/octet-stream";

Hope it helps!
Deenuji at 28-Jan-13 6:34am
superb sir....but how to select that particular link and redirect to open??????
Deenuji at 28-Jan-13 6:37am
for example i have link like C:\Users\FABS\Documents\Xml Search\upload\count.xml in can i pass this selected link to open through redirect??????
_Amy at 28-Jan-13 6:41am
Pass it using CommandArgument property of LinkButton. Try my updated answer.. All the best.
Deenuji at 28-Jan-13 6:46am
Error Creating Control -'System.Web.UI.WebControls.HyperLinkField' does not have a public property named 'CommandName' ....
I'm getting this error sir...
_Amy at 28-Jan-13 6:48am
You should use LinkButton not HyperLink.. Check my answer carefully.
Deenuji at 28-Jan-13 7:21am
Actually i can't find link button in that have only hyperlink what to do sir?
_Amy at 28-Jan-13 7:25am
You need to change it to LinkButton. Try replacing your asp:HyperLink to asp:LinkButton. If you are still unable to do that then paste your HTML code here. I'll check that.
Deenuji at 28-Jan-13 7:32am
now i'm trying with this coding

<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:HyperLinkField DataTextField="Result" DataNavigateUrlFields="Result" DataNavigateUrlFormatString="Show.aspx?Result={0}" Text="Result"
HeaderText="Link" />

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Bind("Result") + Request.QueryString("type") %>'

_Amy at 28-Jan-13 7:36am
Add the following in your GridView:


<asp:LinkButton ID="lnkView" runat="server" Text="View Document" CommandName="View" CommandArgument='<%#EVal("Result")%>'/>
Deenuji at 28-Jan-13 7:42am
After that what i do to select that particular link and view that file????
Deenuji at 28-Jan-13 7:48am
Error is The name 'EVal' does not exist in the current what we declare the value for Eval???? thn whr v ve to declare this???
_Amy at 28-Jan-13 8:30am
It's not EVal its Eval. Sorry I mistyped that word.
Deenuji at 28-Jan-13 8:42am
sir again doubt????
_Amy at 28-Jan-13 22:33pm
Check the link below for similar post:
Open PDF file on button click or hyperlink from[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Abhinav S 275
1 Palash Mondal_ 190
2 KrunalRohit 150
4 Manas_Kumar 115
0 OriginalGriff 3,877
1 KrunalRohit 2,526
2 Maciej Los 2,245
3 CPallini 2,240
4 ppolymorphe 1,750

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100