Using Items.Context with Server.Transfer
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.ConfigurationSe ttings.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("Or derID") );
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
|