I have a grasp, somewhat, of what session variables are. They are variables defined and exist during the session while an application is running or in this case internet connection to a web site. This allows values to be passed from page to page.
The problem I was investigating was how Antoine was using Hazard_ID as a session variable. The contaminated site information would be displayed when the user selected a site from a list. A new page would be displayed based on this selection. I knew he used the Hazard_ID to find which data to fill the page, but I did not know how he accomplished this.
I was trying to use the following to do so:
GridViewRow row = GridView1.SelectedRow;
txtHazard_ID.Text = Convert.ToString(row.Cells[1].Text);
Hazard_ID = Convert.ToInt32(txtHazard_ID.Text);
GridView1 is the ID of my gridview which displays the table of my data. SelectRow returns which row was selected. row now points to the selected row of GridView1. I then convert to string the values of the second column of the selected row of data. I set Hazard_ID to this value and see if this works with his EditSite.aspx page. Hazard_ID is the session variable used to determine which site to display.
It did not work. I would get errors like "Index was out of range. Must be non-negative and less than the size of the collection." and others. I apologize for not posting on Friday. This would have documented the problems in more detail.
I then studied Antoine's EditSite.aspx code as well as his Selector.ascx page which selects the site. I borrowed more code to pass this Hazard_ID with no luck.
Some of the code is as follows:
HttpContext.Current.Session[DataKey] = GridView1.SelectedDataKey.Value;
//trip the event
OnSelectorChanged(sender, e);
txtHazard_ID.Text = Convert.ToString(GridView1.SelectedDataKey.Value);
I had to define OnSelectorChanged, DataeKey get and set, Hazard_ID set and get. In the Page_Load section I tried to set the DataKeyNames to HazardID, which is the name of my key.
It did not work.
I left Friday unsuccessful.
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment