Solved

How to assign a variable to the DataNavigateUrlFormatString property of a hyperlinkcolumn in a datagrid.

Posted on 2004-10-05
8
2,162 Views
Last Modified: 2007-12-19
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 DataNavigateUrlFormatString.

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.Mappath(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.SelectedIndex = 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.Mappath(strOldPath))
            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="FolderChange"
                                    autopostback="true" /><p />
                                    
                  <asp:DataGrid
                                    id="dgFileList"
                                    runat="server"
                                    gridlines="none"
                                    AutoGenerateColumns="false"
                                    Font-Name="arial"
                                    showheader="false">
                        <Columns>
                              <asp:HyperLinkColumn
                                    DataNavigateUrlField="Name"
                                    DataNavigateUrlFormatString="staticfolder/{0}"
                                    DataTextField="Name"
                                    Target="_Blank" />
                        </Columns>
                  </asp:DataGrid><br />
                  
                  <asp:label id="lblDocCount" runat="server" />
            </form>
      </body>
</html>[/code]
0
Comment
Question by:narmi2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 12225346
Which part is giving you trouble ?
-Baan
0
 
LVL 1

Author Comment

by:narmi2
ID: 12225362
the following needs to be dynamic, i dont know if thats possible without changing the whole solution:

DataNavigateUrlFormatString="staticfolder/{0}"

i need to get the variable "strOldPath into DataNavigateUrlFormatString somehow!
0
 
LVL 5

Expert Comment

by:stumpy1
ID: 12225369
Can you not just assign strPath to DataNavigateUrlFormatString through the VB server code?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 1

Author Comment

by:narmi2
ID: 12225375
True, whats the best way to get around this?
0
 
LVL 1

Author Comment

by:narmi2
ID: 12225385
sorry i miss read your post stumpy.

I dunno how to do that?
0
 
LVL 1

Author Comment

by:narmi2
ID: 12225478
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

DataNavigateUrlFormatString="<%strOldPath%>/{0}"

But this gives the following url

http://192.168.100.16/mainfolder/<%strOldPath%>/test.doc
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12225486
Hi,

replace this
<Columns>
                         <asp:HyperLinkColumn
                              DataNavigateUrlField="Name"
                              DataNavigateUrlFormatString="staticfolder/{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
0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 500 total points
ID: 12225502
This can be done in datagrid's ItemBound event.

Sub dgFileList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        Dim HLCol As HyperLinkColumn
        HLCol = MyDataGrid.Columns(0)
        HLCol.DataNavigateUrlFormatString = "staticfolder/{0}"
End Sub
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question