Solved

Passing a variable to an aspx page

Posted on 2007-03-30
5
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled

751 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