473,378 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to link to text files in datagrid?

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
*-----------------------*
Nov 19 '05 #1
2 2354
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?

--
Scott
http://www.OdeToCode.com/blogs/scott/
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
*-----------------------*

Nov 19 '05 #2
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
*-----------------------*
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Doe | last post by:
Hi I want to convert a column to a link. All examples I have seen works with bound columns. I have the following grid: <asp:datagrid runat="server" id="__theDetailsGrid" cellpadding="2"...
3
by: SStory | last post by:
I have a style sheet for my site. It has various classes in it. It has <A: styles defined for all anchor tags. I have a datagrid in ASP.NET with a stylesheet linked to the page. It defines...
1
by: Darren Clark | last post by:
I have a link button that i would like to be used if the value of the text is NOT 0... So the code below will always make a linkbutton.... However if the value of...
2
by: Luis E Valencia | last post by:
I want a row of the datagrid with a personalized link. The fields of the link are on the select related to the datagrid the link would be accoiones.aspx?iddireccion=2&idindicador=5 I tried...
0
by: Luis E Valencia | last post by:
Read from above to top. I didnt understand. This is the code that fills that datagrid Public Sub pasar(ByVal sender As System.Object, ByVal e As...
5
by: Luis E Valencia | last post by:
I need a link on a datagrid, the link must have fields of the database Like this acciones.aspx?iddireccion=1&idindicador=4 Thanks
2
by: pradeep_TP | last post by:
Hello world, I have a simple datagrid on asp.net web form , in which I am showing a single button column called EDIT. The code in the .aspx files for the same is as below. ...
1
by: VanZandt | last post by:
I have a class(dll) that extends winform datagrid to provide link column in vb.net. I have managed to create a datagrid in c# winforms that shows link in one of the column but when I try to create a...
4
by: Mel | last post by:
I have a datagrid control that has one column displaying a filename. When the link is clicked it opens the file. How do I open a file that resides on a remote server? The code below does not...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.