narmi2
asked on
How to assign a variable to the DataNavigateUrlFormatString property of a hyperlinkcolumn in a datagrid.
I have a vb.net aspx page which allows the user to make certain selections. The value of the selections is stored in a variable called strPath.
I need to somehow get this variable into DataNavigateUrlFormatStrin g.
I have the following code so far
[code]<%@ Page Language="VB" Debug=true explicit="true" aspcompat=true %>
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
Dim strPath As String = "mainfolder"
Dim strOldPath As String
Sub Page_Load(sender as Object, e as EventArgs)
if not Page.IsPostBack then
'## GETTING A MAP OF THE DIRECTORY AND SAVING IT IN A ARRAY
dim oDir as DirectoryInfo = new DirectoryInfo(Server.Mappa th(strPath ))
dim aList as Array = oDir.GetDirectories()
'## BINDING THE DIRECTORY TO THE DROPDOWNLIST AND ADDING AND MAIN
'## DIRECTORY TO THE TOP OF THE LIST
ddlSubFolders.Datasource = aList
ddlSubFolders.DataBind()
ddlSubFolders.Items.Insert (0, strPath)
'## BINDING THE MAIN DIRECTORY TO THE DATAGRID
dgFileList.DataSource = oDir.GetFiles()
dgFileList.DataBind()
lblDocCount.text = "<font color=#4B92D9>" & dgFileList.items.count & "</font> document(s) found"
end if
End Sub
'## CHANGES THE DIRECTORY BASED ON THE SELECTED DROPDOWNLIST ITEM
Sub FolderChange(sender as Object, e as EventArgs)
'## CHECKS TO SEE IF THE FIRST LISTITEM IS SELECTED OR NOT
if ddlSubFolders.SelectedInde x = 0 then
strOldPath = strPath
Else
strOldPath = strPath & "/"
strOldPath = strOldPath & ddlSubFolders.SelectedItem .Text
End If
'## REBINDS THE PAGES WITH THE NEW DIRECTORY INFORMATION
dim oDir as DirectoryInfo = new DirectoryInfo(Server.Mappa th(strOldP ath))
dgFileList.DataSource = oDir.GetFiles()
dgFileList.DataBind()
lblDocCount.text = "<font color=#4B92D9>" & dgFileList.items.count & "</font> document(s) found"
End Sub
</script>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<form id="form1" method="Post" runat="server">
<asp:Label
id="page_title"
Font-Size="11"
Font-Name="Arial"
Font-Bold="true"
ForeColor="#00436c"
text=""
runat="server" /><br />
<asp:dropdownlist
id="ddlSubFolders"
Font-Name="Arial"
font-size="8"
runat="server"
OnSelectedIndexChanged="Fo lderChange "
autopostback="true" /><p />
<asp:DataGrid
id="dgFileList"
runat="server"
gridlines="none"
AutoGenerateColumns="false "
Font-Name="arial"
showheader="false">
<Columns>
<asp:HyperLinkColumn
DataNavigateUrlField="Name "
DataNavigateUrlFormatStrin g="staticf older/{0}"
DataTextField="Name"
Target="_Blank" />
</Columns>
</asp:DataGrid><br />
<asp:label id="lblDocCount" runat="server" />
</form>
</body>
</html>[/code]
I need to somehow get this variable into DataNavigateUrlFormatStrin
I have the following code so far
[code]<%@ Page Language="VB" Debug=true explicit="true" aspcompat=true %>
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
Dim strPath As String = "mainfolder"
Dim strOldPath As String
Sub Page_Load(sender as Object, e as EventArgs)
if not Page.IsPostBack then
'## GETTING A MAP OF THE DIRECTORY AND SAVING IT IN A ARRAY
dim oDir as DirectoryInfo = new DirectoryInfo(Server.Mappa
dim aList as Array = oDir.GetDirectories()
'## BINDING THE DIRECTORY TO THE DROPDOWNLIST AND ADDING AND MAIN
'## DIRECTORY TO THE TOP OF THE LIST
ddlSubFolders.Datasource = aList
ddlSubFolders.DataBind()
ddlSubFolders.Items.Insert
'## BINDING THE MAIN DIRECTORY TO THE DATAGRID
dgFileList.DataSource = oDir.GetFiles()
dgFileList.DataBind()
lblDocCount.text = "<font color=#4B92D9>" & dgFileList.items.count & "</font> document(s) found"
end if
End Sub
'## CHANGES THE DIRECTORY BASED ON THE SELECTED DROPDOWNLIST ITEM
Sub FolderChange(sender as Object, e as EventArgs)
'## CHECKS TO SEE IF THE FIRST LISTITEM IS SELECTED OR NOT
if ddlSubFolders.SelectedInde
strOldPath = strPath
Else
strOldPath = strPath & "/"
strOldPath = strOldPath & ddlSubFolders.SelectedItem
End If
'## REBINDS THE PAGES WITH THE NEW DIRECTORY INFORMATION
dim oDir as DirectoryInfo = new DirectoryInfo(Server.Mappa
dgFileList.DataSource = oDir.GetFiles()
dgFileList.DataBind()
lblDocCount.text = "<font color=#4B92D9>" & dgFileList.items.count & "</font> document(s) found"
End Sub
</script>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<form id="form1" method="Post" runat="server">
<asp:Label
id="page_title"
Font-Size="11"
Font-Name="Arial"
Font-Bold="true"
ForeColor="#00436c"
text=""
runat="server" /><br />
<asp:dropdownlist
id="ddlSubFolders"
Font-Name="Arial"
font-size="8"
runat="server"
OnSelectedIndexChanged="Fo
autopostback="true" /><p />
<asp:DataGrid
id="dgFileList"
runat="server"
gridlines="none"
AutoGenerateColumns="false
Font-Name="arial"
showheader="false">
<Columns>
<asp:HyperLinkColumn
DataNavigateUrlField="Name
DataNavigateUrlFormatStrin
DataTextField="Name"
Target="_Blank" />
</Columns>
</asp:DataGrid><br />
<asp:label id="lblDocCount" runat="server" />
</form>
</body>
</html>[/code]
ASKER
the following needs to be dynamic, i dont know if thats possible without changing the whole solution:
DataNavigateUrlFormatStrin g="staticf older/{0}"
i need to get the variable "strOldPath into DataNavigateUrlFormatStrin g somehow!
DataNavigateUrlFormatStrin
i need to get the variable "strOldPath into DataNavigateUrlFormatStrin
Can you not just assign strPath to DataNavigateUrlFormatStrin g through the VB server code?
ASKER
True, whats the best way to get around this?
ASKER
sorry i miss read your post stumpy.
I dunno how to do that?
I dunno how to do that?
ASKER
to give you a better understanding of the problem, the hyperlinks produce the following url
http://192.168.100.16/mainfolder/staticfolder/test.doc
I need the staticfolder bit to be dynamic.
I thought I would simply be able to do something like
DataNavigateUrlFormatStrin g="<%strOl dPath%>/{0 }"
But this gives the following url
http://192.168.100.16/mainfolder/<%strOldPath%>/test.doc
http://192.168.100.16/mainfolder/staticfolder/test.doc
I need the staticfolder bit to be dynamic.
I thought I would simply be able to do something like
DataNavigateUrlFormatStrin
But this gives the following url
http://192.168.100.16/mainfolder/<%strOldPath%>/test.doc
Hi,
replace this
<Columns>
<asp:HyperLinkColumn
DataNavigateUrlField="Name "
DataNavigateUrlFormatStrin g="staticf older/{0}"
DataTextField="Name"
Target="_Blank" />
</Columns>
with this
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink id="hl" runat="server" NavigateUrl="<%# DataBinder.Eval(Container. DataItem, "strOldPath") %>/<%# DataBinder.Eval(Container. DataItem, "Name") %>" Text="<%# DataBinder.Eval(Container. DataItem, "Name") %>
" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
Regards,
B..M
replace this
<Columns>
<asp:HyperLinkColumn
DataNavigateUrlField="Name
DataNavigateUrlFormatStrin
DataTextField="Name"
Target="_Blank" />
</Columns>
with this
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink id="hl" runat="server" NavigateUrl="<%# DataBinder.Eval(Container.
" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
Regards,
B..M
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
-Baan