Visual Studio .NET - Dynamically setting DataNavigateUrlFormatString

Asked By Jon Paskett on 08-Aug-08 09:57 AM

I have a datagrid displaying the files of a Virtual Directory. If I hard code the DateNavigateUrlFormatString = "~/VirDir/{0}" I'm able to open the files. I want to set the string in the Page Load Event of the code behind because the VirDir string comes from a database query. I have been unsuccesful in setting this string to the proper value. Any help would be appreciated.

Jon

Dynamically setting DataNavigateUrlFormatString

Partha Mandayam replied to Jon Paskett on 08-Aug-08 11:33 AM
Use something like this in the page_load

Dim instance As HyperLinkField
Dim value As String



instance.DataNavigateUrlFormatString = value
Now the value can be dynamically created and asssigned

Dynamically setting DataNavigateUrlFormatString

Sakshi a replied to Jon Paskett on 08-Aug-08 12:43 PM

1.

DavaNavigateUrlFormatString='<%# ... %>'

2.

<asp:DataGrid id="DataGrid1" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:HyperLinkColumn HeaderText="ID" DataNavigateUrlField="ID"
DataNavigateUrlFormatString="link.aspx?id={0}"
DataTextField="ID"></asp:HyperLinkColumn>
</Columns>
</asp:DataGrid>

3

<asp:DataGrid id="DataGrid1" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:BoundColumn DataField="ID" HeaderText="ID"></asp:BoundColumn>
<asp:HyperLinkColumn HeaderText="Link" DataNavigateUrlField="Link"
DataNavigateUrlFormatString="{0}"
DataTextField="Link"></asp:HyperLinkColumn>
</Columns>
</asp:DataGrid>

4

<asp:DataGrid id="DataGrid1" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:HyperLinkColumn HeaderText="Link" DataNavigateUrlField="Link"
DataNavigateUrlFormatString="http://{0}"
DataTextField="Link"></asp:HyperLinkColumn>
</Columns>
</asp:DataGrid>

Reply

Binny ch replied to Jon Paskett on 08-Aug-08 12:56 PM

Set the Properties.

((HyperLinkColumn)(Exports.Columns[0])).DataNavigateUrlFormatString = "Workflow.aspx?Id={0}";


set DataNavigateURLFields property if you want to access any specific values from the row.

You can get ahelp from this code:

http://www.sitepoint.com/forums/showthread.php?t=373146

Reply
Jon Paskett replied to Sakshi a on 08-Aug-08 01:28 PM

None of these will work for a virtual directory. The Virtual directory URL is http://mysite.com/virDir  and when I hard code the DataNavigateUrlFormatString = "~/VirDir/{0}" everything works fine. I store the virtual directory string in a table and retrieve it during the page load event. I may need to move the process to a different event possibly, but I need to dynamically populate the DataNavigateUrlFormatString to equal this "~/VirDir/{0}" . I'm thinking the databinding event. Any ideas? Here is my Page Load event:

            Dim mySqlString As New StringBuilder()
            mySqlString.Append("SELECT SettingValue ")
            mySqlString.Append("FROM {databaseOwner}{objectQualifier}ModuleSettings ")
            mySqlString.Append("WHERE ModuleID = " & ModuleId)

            Using dr As IDataReader = DataProvider.Instance().ExecuteSQL(mySqlString.ToString())
                While dr.Read
                    myPath = Convert.ToString(dr("SettingValue"))
                End While
            End Using

            Dim dirInfo As New IO.DirectoryInfo(Server.MapPath(myPath))
            articleList.DataSource = dirInfo.GetFiles()
            articleList.DataBind()