Solved

Passing a variable to an aspx page

Posted on 2007-03-30
5
200 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

3 Use Cases for Connected Systems

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

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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