Setting DataNavigateURLFormatString in datagrid
Hi I have a datagrid that has only one column which is a hyperlinkcolumn. I load the data from my sql table and it shows all the records fine. I am using datareader to read each record. The hyperlinks are link to files stored on the server. I need to set the DataNavigateURLFormatString for each hyperlink, so that it points to the right file. After reading all the records I am showing them in a datagrid. The problem is that all my links point to the last record read. I am mixing datareader and sqldataadapter. Here is my code in code behind file.
-------------------------------------------------
Private Sub GetFiles(ByVal strName)
Dim strConn As String
'Get connection string from Web.Config
strConn = ConfigurationSettings.AppSettings("ConnectionStrin g")
Dim DName As String = strName
Dim MySQL As String = "Select DDocName from tbl_DocFile where DName=@DName"
Dim cmd As New SqlCommand(MySQL, New SqlConnection(strConn))
cmd.Parameters.Add(New SqlParameter("@DName", DName))
Dim objDR As SqlDataReader
cmd.Connection.Open()
Try
objDR = cmd.ExecuteReader(System.Data.CommandBehavior.Clos eConnection)
While objDR.Read()
sDocName = objDR("DDocName")
If sDocName <> "" Then
Dim strpath As String = "\ordinance\pdffiles\"
Dim hl As HyperLinkColumn
hl = Me.DataGrid1.Columns(0)
hl.DataNavigateUrlFormatString = strpath & sDocName
End If
End While
If sDocName = "" Then
cmd.Connection.Close()
End If
Catch ex As Exception
Dim str As String = ex.ToString
cmd.Connection.Close()
End Try
Me.SqlDataAdapter2.Fill(Me.DataSet11)
Me.DataGrid1.DataBind()
End Sub
--------------------------------------------------------
I want sDocName to be changing for each hyperlink in the datagrid. HTML portion looks like this:-
<aspataGrid id=DataGrid1 style="Z-INDEX: 198; LEFT: 80px; POSITION: absolute; TOP: 920px" runat="server" Width="400px" Height="58px" DataMember="tbl_DocFile" AutoGenerateColumns="False" DataSource="<%# DataSet11 %>" PageSize="4" AllowPaging="True" ShowHeader="False">
<AlternatingItemStyle Font-Size="XX-Small" Font-Names="Arial"></AlternatingItemStyle>
<ItemStyle Font-Size="XX-Small" Font-Names="Arial"></ItemStyle>
<HeaderStyle Font-Size="XX-Small" Font-Names="Arial"></HeaderStyle>
<FooterStyle Font-Size="XX-Small" Font-Names="Arial"></FooterStyle>
<Columns>
<asp:HyperLinkColumn Text="DDocName" Target="_blank" DataNavigateUrlField="DDocName" DataTextField="DDocName"></asp:HyperLinkColumn>
</Columns>
</aspataGrid>
|