Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QuryString in a CustomControl

Status
Not open for further replies.

JLizOB

Programmer
Dec 5, 2007
45
CA
Hi I am overriding the CreateChildControls method, in a separate class, of the gridview to create a custom gridiview. Is there anyway I can access the querystrings from the URL in this class? Thanks!

 
Nevermind I had to put Page.Request.QueryString["ID"] rather than just using Request.Querystring["ID"].
 
this method ties the grid to the query string. a more flexible solution would be to create public property and assign the value from the calling page/user control.

this this method an error could occur if the url is not properly formatted.

Code:
public class MyGridView : GridView
{
   private int id;

   public void SetId(int id)
   {
      this.id = id;
   }
}
then on the page assign the value
Code:
MyGridView grid = new MyGridView();
grid.SetId(int.Parse(Request.QueryString["Id"]));
//or
grid.SetId(1);
//or
grid.SetId(From.SomewhereElse());

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top