Solved

Passing a variable to an aspx page

Posted on 2007-03-30
5
197 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
gridview is not empty and yeah it includes rows with the ID value...
0
 

Author Comment

by:mrperfect75000
Comment Utility
Got it to work! thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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 …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

11 Experts available now in Live!

Get 1:1 Help Now