473,809 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid - HyperlinkColumn and variables

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.

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

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(S erver.MapPath(s trPath))
'this part works fine
gridFiles.DataS ource = strDirector.Get Files("*" & strFilter & "*")
'I can filter the files I want to show
gridFiles.DataB ind()
' 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
4846
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" DataNavigateUrlFormatString="http://www.aaa.com?Name={0}" SortExpression="NAME" />
4
280
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 id="dgNewsLinks" DataKeyField="News_ID" runat="server" Width="283px" AutoGenerateColumns="False" GridLines="None" ShowHeader="False"> <Columns> <asp:HyperLinkColumn Target="_parent" DataNavigateUrlField="url"
2
1332
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, the link style of the Datagrid must be different from the others.. Even if I set all the format of the datagrid, everything changes... except the link style. Anyone know any way to fix this? I do not know even if I could do this in the css...
2
1712
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: Text="<%Container.DataItem(Name) %>" I would really appritiate any help!
0
240
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 onMouseOver an icon in the datagrid! Some how I need each icon to have a different id that relates to an image record in a database... At the moment I'm using Active Directory to pull the users details from...
1
2827
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 in varying search criteria, hits "search", info is passed to a stored proc, results return and displayed in the datagrid. Every field in the datagrid is numeric (indicative of a certain sum or total) data but also functions as a...
4
4409
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 colors changing, and I have the routine, but I can't seem to get the HyperLinkColumn to fire.... Private Sub MyDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles...
0
1932
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" AutoGenerateColumns="False" Font-Size="8pt" PagerStyle-Wrap="True" AllowSorting="True" CellSpacing="2" CellPadding="3" GridLines="Vertical" ItemStyle-Wrap=True HeaderStyle-Wrap=True
2
1674
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(). ******************************************************** Sub GetFileList() Dim dirInfo as DirectoryInfo = new DirectoryInfo(Server.MapPath("/uploads/"))
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10640
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10387
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.