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
*-----------------------*
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
*-----------------------*