views:

102

answers:

3

Hi, I have a web app (ASP.NET 2.0 C#)where I get data from an Oracle database into a gridview. I had asked in a previous question how I could turn that data into links that would, for example, take me to a details page. This was the answer I got:

<asp:HyperLinkField DataNavigateUrlFields="ID"
     DataNavigateUrlFormatString="DetailPage.aspx?id={0}"
                        DataTextField="CategoryName" NavigateUrl="DetailPage.aspx" />

Doing this makes the ID's links, and once I click it, the ID is in the URL of the next page.

My question is, how am I supposed to use this data from the URL to actually display the information about that ID? Do I have to do something to my code behind?

Thank you

A: 

Yes in your code behind you'll need to grab the id from the query string, send it to the database, and wire the return value up to the display elements.

You might be able to achieve this using the DataSource if they can pull parameters from a query string.

JoshBerke
A: 

On the page load of the DetailPage use the QueryString to get the id

if(!IsPostBack)
{
    try
    {
        intMyId = (int)Request.QueryString["id"];
        //Do something with intMyId
    }
    catch(InvalidCastException ex)
    {
       //Record and show error message
    }
}

NOTE: You will want to verify that the id is a valid id because an attacker could put whatever they want in there. Also verify that the user can view the id.

Nathan Koop
A: 

you can use query string to extract data from your url..

Syed Tayyab Ali