user710502
user710502

Reputation: 11469

HyperLink field in Gridview (Url Navigation)

At work there is a gridview and it has the following syntax

  <asp:HyperLinkField 
    DataNavigateUrlFields="NameID" 
    DataNavigateUrlFormatString="names.aspx?nameid={0}"
    DataTextField="name" 
    HeaderText="Client Name" 
    SortExpression="Name" 
    ItemStyle-Width="100px"
    ItemStyle-Wrap="true" />

So I added the line DataNavigateUrlFormatString... The link is showing properly but the address looks like this

http://.....clients/clientNames/names.aspx?nameid=123

This gridview is in the ClientsNames folder.. but I actually want to use the names.aspx of the maintenance folder... so Basically i want the URL to redirect like this

httpL//....clients/Maintenance/names.aspx?nameid=123

I tried to add DataNavigateUrlFormatString="Maintenance/names.aspx?nameid={0}" but instead it would create url like this

http://......clients/clientNames/Mainteanance/names.aspx?nameid=123

How can I make it so that the url looks like this from this grid view?

http://.....clients/Maintenance/names.aspx?nameid=123

Thank you

Upvotes: 2

Views: 7417

Answers (3)

Chains
Chains

Reputation: 13167

There's all kinds of wierd prefixes to try... I don't have a reference off-hand, but here are some:

DataNavigateUrlFormatString="~/names.aspx?nameid={0}" (starts at the root)
DataNavigateUrlFormatString="../names.aspx?nameid={0}" (starts in the parent's parent folder)
DataNavigateUrlFormatString="../../names.aspx?nameid={0}" (starts in the parent's parent's parent's folder)

Upvotes: 1

Tomas Voracek
Tomas Voracek

Reputation: 5914

Use

DataNavigateUrlFormatString="~/clients/Maintenance/names.aspx?nameid={0}"

Or you can use GridView.RowDataBound event and set Url programmatically.

Upvotes: 1

NoAlias
NoAlias

Reputation: 9193

Try setting DataNavigateUrlFormatString to "../Maintenance/names.aspx?nameid={0}"

  <asp:HyperLinkField      
  DataNavigateUrlFields="NameID"
  DataNavigateUrlFormatString="../maintenance/names.aspx?nameid={0}"
  DataTextField="name"
  HeaderText="Client Name"
  SortExpression="Name"
  ItemStyle-Width="100px"
  ItemStyle-Wrap="true" /> 

Upvotes: 4

Related Questions