Solved

Passing a variable to an aspx page

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now