Hi,
I'd use a template column and a helper function to add the variable. Here's
a little sample below.
Let us know if this helps?
Ken
Microsoft MVP [ASP.NET]
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<script runat="server">
Dim strPath As String = "mypath"
Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArg s)
If Not IsPostBack Then
datagrid1.DataS ource = CreateDataSourc e()
datagrid1.DataB ind()
End If
End Sub
Function AddPath(ByVal inString As String) As String
Return strPath & "\" & inString
End Function
Function CreateDataSourc e() As Data.DataTable
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
dt.Columns.Add( New Data.DataColumn _
("IntegerValue" , GetType(Int32)) )
dt.Columns.Add( New Data.DataColumn _
("strFile", GetType(String) ))
dt.Columns.Add( New Data.DataColumn _
("CurrencyValue ", GetType(Double) ))
dt.Columns.Add( New Data.DataColumn _
("Boolean", GetType(Boolean )))
Dim i As Integer
For i = 0 To 5
dr = dt.NewRow()
dr(0) = i
dr(1) = "file" + i.ToString() & ".aspx"
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Helper Function</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="datagrid1" runat="server" autogeneratecol umns="False">
<columns>
<asp:templateco lumn headertext="Fil e">
<itemtemplate >
<asp:hyperlin k
runat="server"
navigateurl='<% # AddPath(DataBin der.Eval(Contai ner,
"DataItem.strFi le")) %>'
text='<%# DataBinder.Eval (Container, "DataItem.strFi le")
%>'>
</asp:hyperlink>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>
</div>
</form>
</body>
</html>
"Jl_G_0" <jl*********@gm ail.comwrote in message
news:11******** **************@ d34g2000cwd.goo glegroups.com.. .
Hey all, I need to add a hyperlinkcolumn to a datagrid, but the path
(DataNavigateUr lFormatString) is dynamic, since the page lists files in
directories. The folder name to list is stored in a variable (strPath).
The code that I tried is: DataNavigateUrl FormatString='< %#strPath
%>/{0}'
But it says: "Databindin g expressions are only supported on objects
that have a DataBinding event"
Anyway I could place my variable on that field, using another way, or
what Im doing wrong ? I searched for this problem and find some info
about TemplateColumns too, can I insert variables onto it ?
Thanks for helping.