Solved

Passing a variable to an aspx page

Posted on 2007-03-30
5
203 Views
Last Modified: 2010-04-16
Hi Experts - Please help Urgent please....

I need help with a page query. I have this code that filters a data set  -- my problem is that i want to pass an id thru the URL and have it filter - i thought this should be able to do it - but i dont now if i'm missing something.

 It doesnt seem to be working when i try to pass a value to it like general.aspx?id=6677 How can i make it filter once i pass a value to id?

 Please help!! thaks

DataSet ds = new DataSet();

               ds = objectArray.ToDataSet();


      DataView dv = ds.Tables[0].DefaultView;
        if (Page.Request.QueryString["id"] != null)
        {
               string id = Page.Request.QueryString["id"];
                 dv.RowFilter = "id = " + id;
        }
        GridView1.DataSource = dv;
        GridView1.DataBind();
0
Comment
Question by:mrperfect75000
  • 3
5 Comments
 
LVL 35

Accepted Solution

by:
YZlat earned 400 total points
ID: 18824101
if id is a string, try

if (Page.Request.QueryString["id"] != null)
        {
               string id = Page.Request.QueryString["id"];
                 dv.RowFilter = "id =' " + id + " ' ";
        }

and if id is an integer, try

if (Page.Request.QueryString["id"] != null)
        {
               int id = Page.Request.QueryString["id"];
                 dv.RowFilter = "id =" + id;
        }

0
 

Author Comment

by:mrperfect75000
ID: 18824239
Thanks - That doesnt seem to work either . It is a string ...

so i tried general.aspx?id=text and it just gives an empty page. Not sure what i'm doing wrong.
0
 
LVL 25

Assisted Solution

by:dstanley9
dstanley9 earned 100 total points
ID: 18824396
Your gridview may just be empty.  Does your data include rows with that ID value?

And query strings are _always_ strings.  you have to parse it to get other data types.  
0
 

Author Comment

by:mrperfect75000
ID: 18824490
gridview is not empty and yeah it includes rows with the ID value...
0
 

Author Comment

by:mrperfect75000
ID: 18826191
Got it to work! thanks
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question