1

In my ASP.NET Web Forms I would like to get the DataNavigateUrlFields from the HyperLinkField control.

In order to get the control I use the following code in the RowDataBound event:

If e.Row.Cells(n).Controls(0).GetType().ToString() = "System.Web.UI.WebControls.HyperLink" Then
     Dim linkDownload As HyperLink = DirectCast(e.Row.Cells(n).Controls(0), HyperLink)

The problem is that I get an HyperLink already "filled" so the DataNavigateURLFormatString (myPage.aspx?downloadId = {0}) and DataNavigateUrlFields (downloadGuid) are already combined in the HyperLink.NavigateUrl property.

Is there any way to get the DataNavigateUrlFields property? In case there is not, is there any function to extract the downloadGuid value from HyperLink.NavigateUrl (in short treating the NavigateUrl as a QueryString)?

VB is preferred but also answers in C# are appreciated

Taz
  • 3,718
  • 2
  • 37
  • 59
CiccioMiami
  • 8,028
  • 32
  • 90
  • 151

2 Answers2

3

If you got the url, you can use Url class to manipulate it. It also allows to extract parameters and values. There's regexp option available too.

But where's downloadGuid in DataNavigateUrlFields (downloadGuid) coming from? You should get your bound object in the RowDataBound event parameters, if downloadGuid is the property, you can grap if from there.

Anyways, full event code will certainly help.

b0rg
  • 1,879
  • 12
  • 17
  • Thanks. Let's say I have the URL in NavigateUrl property. I can convert it to URL and then extract the parameters? How? Thanks!!! – CiccioMiami Mar 01 '12 at 15:21
  • totally lazy aren't we? :) http://stackoverflow.com/questions/659887/get-url-parameters-from-a-string-in-net – b0rg Mar 01 '12 at 15:40
  • thanks, no I was trying another approach by using multiple Split functions with (?), (&) and (=) as separators. The first split divides the address from the parameters. Then with the second I create an array of parameters (key=value) and with the third I divide the key from the value and I can put it in a Dictionary for instance ;-) – CiccioMiami Mar 01 '12 at 16:39
2

Why can not you get it like

 if(e.Row.RowType==DataControlRowType.DataRow)
                Response.Write(((DataRowView)e.Row.DataItem)["downloadGuid"]);
PraveenVenu
  • 8,217
  • 4
  • 30
  • 39