Subject: Using Items.Context with Server.Transfer
Posted By: jazzcatone Post Date: 8/27/2006 4:53:38 PM
Hello and thank you for taking a moment to read this message. I am trying to use Items.Context (from HttpCollection)  with Server.Transfer to pass the selected value of a asp dropdown box( autopostback="True") to a second web page. The value I want passed  is essentially an order number. The second webpage will display a datagrid with information about the order number passed. I am using 1.1 framework. The relevant Code Behind for the 1st page( the page passing the value) is this:


--------------------------------------------------------------------------------

private void DropListChanged(Object sender,EventArgs e)

{//Storing in Context

Context.Items("OrderID") = DropDownList1.SelectedItem;

Server.Transfer("ordergrid.aspx");

}


--------------------------------------------------------------------------------
I then want to pass the value as a parameter to my stored procedure on the second page to make the data grid work:
--------------------------------------------------------------------------------

//Get the connection string from the web config and open the connection

SqlConnection dbConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["NWind"].ToString());

dbConn.Open();

//Get your sql command utilizing the stored procedure


SqlCommand sqlCom = new SqlCommand("usp_retrieve_order_info");

sqlCom.CommandType = CommandType.StoredProcedure;

sqlCom.Parameters.Add("@OrderID",Context.Items("OrderID") );

 

sqlCom.Connection = dbConn;

 

//declare a new dataset


DataSet ds = new DataSet();

//declare the adapter to fill the dataset


SqlDataAdapter da = new SqlDataAdapter(sqlCom);

 

//Fill dataSet DS with results set and name the filled table "tblOrders"


da.Fill(ds, "tblOrders");

//Bind the the dataset to our datagrid

dgrdOrders.DataSource =ds;

dgrdOrders.DataBind();


--------------------------------------------------------------------------------

The problem is that VS looks at the code I have in bold above, it keeps throwing me the error: c:\inetpub\wwwroot\NOrders\ordergrid.aspx.cs(37): 'System.Web.HttpContext.Items' denotes a 'property' where a 'method' was expected

I know that you can use thisContext.Items to pass data but I'm just not sure what I'm doing wrong. I have spent a considerable amount of time reading up on the HttpContext class, but to no avail. If there is any one who can help me gain a better understanding on the process I would be greatly appreciative. Thank you in advance.

Jason




Go to topic 48501

Return to index page 192
Return to index page 191
Return to index page 190
Return to index page 189
Return to index page 188
Return to index page 187
Return to index page 186
Return to index page 185
Return to index page 184
Return to index page 183