Pomster
Pomster

Reputation: 15197

How to get the value of DataNavigateUrlFields?

I have a DataTable and it is passing a value though a DataNavigateUrlField.

In code what do I type to get that value, e.g.:

MessageNum = DataNavigateUrlField[MessageNumber];

Here i have DataNavigateUrlFields="MessageNumber", What in my C# Code can i do to get the value of MessageNumber?? Please i need help.

<asp:HyperLinkField
    HeaderText="Subject"
    DataNavigateUrlFields="MessageNumber" 
    DataNavigateUrlFormatString="~/ViewMailContent.aspx?MessageNumber={0}"
    DataTextField="Subject" />

The DataTable is set as a GridView.DataSource, and then sent to a page, the user selects a hyperlink and then the page navigates, i need the message number selected.

I noticed The Value is showing on the top of my Screen in the Url and its the correct value, but how do i get the value, and is it possible to get the value before the Page navigates? else The page will have to load twice i think.

I started web about a week ago so not give me extreme web lingo.

Upvotes: 1

Views: 2548

Answers (1)

mortb
mortb

Reputation: 9869

You have (at least) two options:

  1. If you need the value in the destination page (the page that you navigate to by clicking the url in the grid) you'll just write

    Example (in code behind):

    Request.QueryString("MessageNumber")
    
  2. If you need the value in the page that has the grid you'll rewrite the url to point to a javascript function, which in turn may redirect to the destination page.

    <asp:HyperLinkField
        HeaderText="Subject"
        DataNavigateUrlFields="MessageNumber" 
        DataNavigateUrlFormatString="javascript:myFunction({0})"
        DataTextField="Subject" />
    

    The function (should be in a javascript block in source page):

    function myFunction(id)
    { 
        alert("Now you are leaving this page");
        document.location = "ViewMailContent.aspx?MessageNumber=" + id;
    }
    

Upvotes: 4

Related Questions