473,395 Members | 1,999 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,395 software developers and data experts.

Datagrid - HyperlinkColumn and variables

Hey all, I need to add a hyperlinkcolumn to a datagrid, but the path
(DataNavigateUrlFormatString) 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: DataNavigateUrlFormatString='<%#strPath
%>/{0}'

But it says: "Databinding 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.

Sep 12 '06 #1
3 4294
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.dtd">

<script runat="server">
Dim strPath As String = "mypath"
Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)

If Not IsPostBack Then
datagrid1.DataSource = CreateDataSource()
datagrid1.DataBind()
End If
End Sub

Function AddPath(ByVal inString As String) As String
Return strPath & "\" & inString
End Function

Function CreateDataSource() 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" autogeneratecolumns="False">
<columns>
<asp:templatecolumn headertext="File">
<itemtemplate>
<asp:hyperlink
runat="server"
navigateurl='<%# AddPath(DataBinder.Eval(Container,
"DataItem.strFile")) %>'
text='<%# DataBinder.Eval(Container, "DataItem.strFile")
%>'>
</asp:hyperlink>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
</div>
</form>
</body>
</html>

"Jl_G_0" <jl*********@gmail.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
Hey all, I need to add a hyperlinkcolumn to a datagrid, but the path
(DataNavigateUrlFormatString) 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: DataNavigateUrlFormatString='<%#strPath
%>/{0}'

But it says: "Databinding 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.

Sep 12 '06 #2
thanks for helping. This helped me out because I learned to use a
template column, but im having a hard time to convert my code that
lists files on a folder using a DataGrid:

strDirector = New DirectoryInfo(Server.MapPath(strPath))
'this part works fine
gridFiles.DataSource = strDirector.GetFiles("*" & strFilter & "*")
'I can filter the files I want to show
gridFiles.DataBind()
' then I bind the data to the grid

Since I have the files on the DataGrid (gridFiles), I have one
HyperlinkColumn that creates one link to each file, and then I can
access it.

I just need to configure the path so when I click the link it really
opens the file, I can't hardcode the path because since I only have one
page, it 'should' use a variable to set the path.

Right now im trying to create a template column inside my datagrid,
hope Im doing the right thing.

thks again for showing me how to use template columns.

Sep 12 '06 #3

it worked fine... template columns aren't that hard now... I think.
thanks again.

Sep 13 '06 #4

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

Similar topics

0
by: Jongmin | last post by:
Hi! I am making HyperLinkColumn in datagrid. It is simple to make the hyerlinkcolumn with one datafield. <asp:HyperLinkColumn Text="NAME" DataNavigateUrlField="NAME"...
4
by: cooltech77 | last post by:
hi all, I am a newbie and i need some help.I have datagrid on my asp.net page which has hyperlink columns. the datagrid configuration in the aspx page is as follows <asp:DataGrid...
2
by: ltt19 | last post by:
Hi. I have a DataGrid control that has one HyperLinkColumn, and this page has a "default.css" loaded, so, the link Style of the DataGrid is the same of the css document... but I want to change it,...
2
by: Tim::.. | last post by:
Hi Can someone please tell me why my datagrid doesn't populate with data properly... For some reason the DataNavigateUrlFormatString populates ok but Text doesn't??? E.G:...
0
by: Tim::.. | last post by:
Can someone please tell me how I can get the following JavaScript to work inside this datagrid! What I'm trying to do is to have a layer that shows up with an image of an employee when you...
1
by: Roy | last post by:
I'm assuming this is amazingly simple and I'm just missing the boat. On the html side of an asp.net page I have a datagrid, a "search" button, and 8 text boxes for search criteria. A user enters...
4
by: sakieboy | last post by:
I currently have a datagrid with several columns. The first column in the DataGrid is a HyperLinkColumn. When I select a row, I would like for this HyperlinkColumn to fire. I have the mouseover...
0
by: virendra.chandra | last post by:
in datagrid cellpadding is not working. can u suggest what could be the possible error. this is my code <asp:datagrid id="test1" Runat="server" Width="700" Enabled="True"...
2
by: tshad | last post by:
I am having a problem with my Datagrid that displays my Files via GetFiles() If I use a HyperLinkColumn - I can use the column name "Name" which is what the result from GetFiles(). ...
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:
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.