How to link to text files in datagrid?

J

JenHu

hi,

I have a datagrid in my asp.net application, I am using vb.net
language.
I want to have my last column as a link column, link to text file.
The link path is "c:\Temp\" & F_File_Name, which is the 2nd
column.

For example, the data grid should like this:

Batch # File Name File Status File link
1 EF010405.txt Rows entered Link (when user click it, it should
link to c:\temp\EF010405.txt)

I searched the web and didn't find any sample code for file linkage
throw hyperlink column in a datagrid, can someone show me how to do
it?

Thank you.

Here is the Html:
-----------------------------------------------
<asp:datagrid id="dgFundStatus" Runat="server" CellPadding="3"
AutoGenerateColumns="False" >
<Columns>
<asp:BoundColumn DataField="F_Batch_Num" HeaderText="Batch
#"></asp:BoundColumn>
<asp:BoundColumn DataField="F_File_Name" HeaderText="File
Name"></asp:BoundColumn>
<asp:BoundColumn DataField="File_Status" HeaderText="File
Status"></asp:BoundColumn>
<asp:HyperLinkColumn HeaderText="File link"
DataNavigateUrlField="FilePath"
DataNavigateUrlFormatString="{0}" DataTextField="File link"
ItemStyle-CssClass="testStyle">
</asp:HyperLinkColumn>
</Columns>
</asp:datagrid>

Here is the code:
------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
BindData()
End If
End Sub

Sub BindData()
Dim strSql As New SqlCommand
Dim dtrDataGrid As SqlDataReader
Dim dataAdapter As New SqlDataAdapter
Dim dataSet As New DataSet
Dim FilePath As String
Try
If Not IsPostBack Then
conEZDb.Open()
strSql.CommandText = "SELECT F.F_Batch_Num,
F.F_File_Name, F.F_Transmit_Date, S.File_Status_Description FROM
Epay_Fund_Batch_Table F INNER JOIN Epay_File_Status S ON
F.F_File_Status = S.File_Status "
strSql.Connection = conEZDb
strSql.CommandType = CommandType.Text
dataAdapter.SelectCommand = strSql
dataAdapter.Fill(dataSet, "Funding")
Dim FundingInfo As DataTable =
dataSet.Tables("Funding")
Dim dvFundingInfo As New
DataView(dataSet.Tables("Funding"))
Session("FundingSession") = dvFundingInfo
dvFundingInfo.Sort = strViewString
dgFundStatus.DataSource = dvFundingInfo

dgFundStatus.DataBind()
conEZDb.Close()
End If
Catch err As Exception
End Try
End Sub

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
S

Scott Allen

Jen:

This approach doesn't work if the browser is not on the same machine as the
server. The user's browser will look to the local C: drive for the file.
You'll want to have the text files underneath the web application (or somewhere
else under a website where IIS can server them from) and put in a link or
relative path to the file.

Make sense?
 
J

JenHu

The reason I put C:\ is because we haven't find the appropreate place,
it's a testing path.

My question is I don't know how to put the path on this code and make
it work.

Can you show me how ?

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top