C# .NET - Repopulate listbox with session var. if index ...

Asked By matt cupryk on 02-Feb-04 05:11 PM
<code>
How do I repopulate the listbox when I come back from the last page if index is saved in a session state? 
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Text;
using System.Xml;
using System.Data.SqlClient;
using System.Globalization;
using System.Text.RegularExpressions;
namespace CuprykWeb
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class signup : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.ListBox lbTitle;
		protected System.Web.UI.WebControls.TextBox txtFirstName;
		protected System.Web.UI.WebControls.RequiredFieldValidator txtFirstNameReqVal;
		protected System.Web.UI.WebControls.RegularExpressionValidator txtFirstNameRegexVal;
		protected System.Web.UI.WebControls.TextBox txtLastName;
		protected System.Web.UI.WebControls.RequiredFieldValidator txtLastNameReqVal;
		protected System.Web.UI.WebControls.RegularExpressionValidator txtLastNameRegexVal;
		protected System.Web.UI.WebControls.TextBox txtCity;
		protected System.Web.UI.WebControls.RegularExpressionValidator txtCityRegexVal;
		protected System.Web.UI.WebControls.RequiredFieldValidator txtCityReqVal;
		protected System.Web.UI.WebControls.ListBox lbStateProvince;
		protected System.Web.UI.WebControls.ListBox lbCountry;
		protected ActiveUp.WebControls.ActiveDateTime BirthDateSelector;
		protected System.Web.UI.WebControls.ListBox lbGender;
		protected System.Web.UI.WebControls.ListBox lbSecretWordType;
		protected System.Web.UI.WebControls.TextBox txtSecretWord;
		protected System.Web.UI.WebControls.RequiredFieldValidator txtSecretWordReqVal;
		protected System.Web.UI.WebControls.RegularExpressionValidator txtSecretWordRegexVal;
		protected System.Web.UI.WebControls.TextBox txtEmail;
		protected System.Web.UI.WebControls.RequiredFieldValidator txtEmailReqVal;
		protected System.Web.UI.WebControls.RegularExpressionValidator txtEmailRegexVal;
		protected System.Web.UI.WebControls.TextBox txtUserName;
		protected System.Web.UI.WebControls.RequiredFieldValidator usernameReqVal;
		protected System.Web.UI.WebControls.CustomValidator UserNameCheckDuplicateValue;
		protected System.Web.UI.WebControls.RegularExpressionValidator usernameRegexVal;
		protected System.Web.UI.WebControls.TextBox txtPassword;
		protected System.Web.UI.WebControls.RequiredFieldValidator txtpasswdReqVal;
		protected System.Web.UI.WebControls.RegularExpressionValidator txtpasswdRegexBal;
		protected System.Web.UI.WebControls.TextBox txtPassword2;
		protected System.Web.UI.WebControls.RequiredFieldValidator txtPassword2ReqVal;
		protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
		protected System.Web.UI.WebControls.TextBox txtHeadLine;
		protected System.Web.UI.HtmlControls.HtmlInputImage InputImage3;
		protected System.Web.UI.WebControls.Label BirthDate;
		protected MetaBuilders.WebControls.FirstFocus FirstFocus1;
		protected System.Web.UI.HtmlControls.HtmlForm Form1;
		// get Connection string from Config.web
		static string m_strConnection = System.Configuration.ConfigurationSettings.AppSettings["sRegistration_FormDBConnectionString"];	//	default connection string
		static SqlDataAdapter title;
		static string batchSQL = "Select * FROM titles; Select * FROM genders; Select * FROM secretwordtypes; Select * FROM states; Select * FROM countries";
		// create a SqlDataAdapter and use it to fill a DataSet SqlDataAdapter title; 
		public void txtUserName_TextChanged(object sender, System.EventArgs e)
		{
		}
		public void txtPassword_TextChanged(object sender, System.EventArgs e)
		{
		}
		public void txtPassword2_TextChanged(object sender, System.EventArgs e)
		{
		}
		public void txtFirstName_TextChanged(object sender, System.EventArgs e)
		{
		}
		public void txtLastName_TextChanged(object sender, System.EventArgs e)
		{
		}
		public void txtEmail_TextChanged(object sender, System.EventArgs e)
		{
		}
		public void lbTitle_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (lbTitle.SelectedItem != null)
			{
				Session["webform1_lbTitle"] = lbTitle.SelectedValue;
			}
		}
		public void txtCity_TextChanged(object sender, EventArgs e)
		{
		}
		public void lbStateProvince_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (lbStateProvince.SelectedItem != null)
			{
				Session["webform1_lbStateProvince"] = lbStateProvince.SelectedValue;
			}
		}
		public void lbCountry_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (lbCountry.SelectedItem != null)
			{
				Session["webform1_lbCountry"] = lbCountry.SelectedValue;
			}
		}
		public void BirthDateSelector_DateChanged(object sender, ActiveUp.WebControls.DateChangedEventArgs e)
		{
			if (BirthDateSelector != null) 
			{
				Session["webform1_BirthDateSelector"] = BirthDateSelector;
			}
		}
		public void lbGender_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (lbGender.SelectedItem != null)
			{
				Session["webform1_lbGender"] = lbGender.SelectedValue;
			}
		}
		public void lbSecretWordType_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (lbSecretWordType.SelectedItem != null)
			{
				Session["webform1_lbSecretWordType"] = lbSecretWordType.SelectedValue;
			}
		}
		public void txtSecretWord_TextChanged(object sender, EventArgs e)
		{
		}   
		public void txtHeadLine_TextChanged(object sender, System.EventArgs e)
		{
		}
		public void BindList(ref System.Web.UI.WebControls.ListBox MyList,
							 DataTable DataSource,
							 string ValueColumnName,
							 string TextColumnName
							 ) 
		{ 
			MyList.DataSource = DataSource; 
			MyList.DataTextField = TextColumnName; 
			MyList.DataValueField = ValueColumnName; 
			MyList.DataBind(); 
		} 
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!IsPostBack)
			{
				// Evals true first time browser hits the page
				DataSet ds = new DataSet(); 
				title = new SqlDataAdapter (batchSQL, m_strConnection); 
				title.Fill (ds);
				// Listbox for Title
				if  (Session["webform1_lbTitle"] == null)
				{
					BindList(ref lbTitle, ds.Tables[0], "title_id", "title_name"); 
				}
				else
				{
					string iSelected =  Session["webform1_lbTitle"].ToString(); 
					ListItem itm;
					itm = lbTitle.Items.FindByValue(iSelected.ToString());
					if (itm!=null) itm.Selected=true;
					Response.Write ("hello" + iSelected);
				}
				// Listbox for Gender
				if  (Session["webform1_lbGender"] == null)
				{
					BindList(ref lbGender, ds.Tables[1], "gender_id", "gender_name"); 
				}
				else
				{
					string iSelected =  Session["webform1_lbGender"].ToString(); 
					ListItem itm;
					itm = lbGender.Items.FindByValue(iSelected.ToString());
					if (itm!=null) itm.Selected=true;
					Response.Write ("hello"+ iSelected);
				}
				// Listbox for Secret Word
				if  (Session["webform1_lbSecretWordType"] == null)
				{
					BindList(ref lbSecretWordType, ds.Tables[2], "secretwordtype_id", "secretwordtype_name"); 
				}
				else
				{
					string iSelected =  Session["webform1_lbSecretWordType"].ToString(); 
					ListItem itm;
					itm = lbSecretWordType.Items.FindByValue(iSelected.ToString());
					if (itm!=null) itm.Selected=true;
					Response.Write ("hello"+iSelected);
				}
				// Listbox for State
				if  (Session["webform1_lbStateProvince"] == null)
				{
					BindList(ref lbStateProvince, ds.Tables[3], "state_id", "state_name"); 
				}
				else
				{
					string iSelected =  Session["webform1_lbStateProvince"].ToString(); 
					ListItem itm;
					itm = lbStateProvince.Items.FindByValue(iSelected.ToString());
					if (itm!=null) itm.Selected=true;
					Response.Write ("hello"+iSelected);
				}
				// Listbox for Country 
				if  (Session["webform1_lbCountry"] == null)
				{
					BindList(ref lbCountry, ds.Tables[4], "country_id", "country_name"); 
				}
				else
				{
					string iSelected =  Session["webform1_lbCountry"].ToString(); 
					ListItem itm;
					itm = lbCountry.Items.FindByValue(iSelected.ToString());
					if (itm!=null) itm.Selected=true;
					Response.Write ("hello"+iSelected);
				}
				if  (!(Session["webform1_txtUserName"] == null))
				{ txtUserName.Text = Session["webform1_txtUserName"].ToString(); }
				if  (!(Session["webform1_txtPassword"] == null))
				{ txtPassword.Text = Session["webform1_txtPassword"].ToString(); }
				if  (!(Session["webform1_txtPassword2"] == null))
				{ txtPassword.Text = Session["webform1_txtPassword2"].ToString(); }
				if  (!(Session["webform1_txtFirstName"] == null))
				{ txtFirstName.Text = Session["webform1_txtFirstName"].ToString(); }
				if  (!(Session["webform1_txtLastName"] == null))
				{ txtLastName.Text = Session["webform1_txtLastName"].ToString(); }
				if  (!(Session["webform1_txtEmail"] == null))
				{ txtEmail.Text = Session["webform1_txtEmail"].ToString(); };
				if  (!(Session["webform1_txtCity"] == null))
				{ txtCity.Text = Session["webform1_txtCity"].ToString(); };
				if (!(Session["webform1_BirthDateSelector"] == null))
				{ BirthDateSelector.Date = (System.DateTime)(Session["webform1_BirthDateSelector"]); };
				if  (!(Session["webform1_txtHeadLine"] == null))
				{ txtHeadLine.Text = Session["webform1_txtHeadLine"].ToString(); }
				if  (!(Session["webform1_txtSecretWord"] == null))
				{ txtSecretWord.Text = Session["webform1_txtSecretWord"].ToString(); };
			}	
		}
		// CODEGEN: This call is required by the ASP.NET Web Form Designer.
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			InitializeComponent();
			base.OnInit(e);
		}
		// <summary>
		// Required method for Designer support - do not modify
		// the contents of this method with the code editor.
		// </summary>
		private void InitializeComponent()
		{
			this.lbTitle.SelectedIndexChanged += new System.EventHandler(this.lbTitle_SelectedIndexChanged);
			this.txtFirstName.TextChanged += new System.EventHandler(this.txtFirstName_TextChanged);
			this.txtLastName.TextChanged += new System.EventHandler(this.txtLastName_TextChanged);
			this.lbStateProvince.SelectedIndexChanged += new System.EventHandler(this.lbStateProvince_SelectedIndexChanged);
			this.lbCountry.SelectedIndexChanged += new System.EventHandler(this.lbCountry_SelectedIndexChanged);
			this.lbGender.SelectedIndexChanged += new System.EventHandler(this.lbGender_SelectedIndexChanged);
			this.lbSecretWordType.SelectedIndexChanged += new System.EventHandler(this.lbSecretWordType_SelectedIndexChanged);
			this.txtPassword.TextChanged += new System.EventHandler(this.txtPassword_TextChanged);
			this.InputImage3.ServerClick += new System.Web.UI.ImageClickEventHandler(this.InputImage3_ServerClick);
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
		public void InputImage3_ServerClick(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if (Page.IsValid) 
			{
				Session["webform1_txtUserName"] = txtUserName.Text;
				Session["webform1_txtPassword"] = txtPassword.Text;
				Session["webform1_txtPassword2"] = txtPassword2.Text;
				Session["webform1_txtFirstName"] = txtFirstName.Text;
				Session["webform1_txtLastName"] = txtLastName.Text;
				Session["webform1_txtEmail"] = txtEmail.Text;
				Session["webform1_txtCity"] = txtCity.Text;
				Session["webform1_BirthDateSelector"] =  BirthDateSelector.Date;
				Session["webform1_txtHeadLine"] = txtHeadLine.Text;
				Session["webform1_txtSecretWord"] = txtSecretWord.Text;
				Server.Transfer("physicalcharacteristics.aspx", true);
			}
		}
	}
}
</code>

Code isn't saving the "index"

Asked By Peter Bromberg on 02-Feb-04 07:56 PM
It's saving the VALUE
public void lbTitle_SelectedIndexChanged(object sender, EventArgs e) 
{ 
if (lbTitle.SelectedItem != null) 
{ 
Session["webform1_lbTitle"] = lbTitle.SelectedValue; 
} 
} 
should be Session["webform1_lbTitle"]=lbTitle.SelectedIndex;
when the page is loaded, simple rebind your listBox 
and then set its selected INDEX to the value in the Session variable.
(if it's not null)

If u can give me an example.

Asked By matt cupryk on 02-Feb-04 10:56 PM
I change my code around.
when the page is loaded, simple rebind the listBox 
and then set its selected INDEX to the value in the Session variable. 
(if it's not null) 
<code>
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Text;
using System.Xml;
using System.Data.SqlClient;
using System.Globalization;
using System.Text.RegularExpressions;
namespace CuprykWeb
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class signup : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.ListBox lbTitle;
		protected System.Web.UI.WebControls.TextBox txtFirstName;
		protected System.Web.UI.WebControls.RequiredFieldValidator txtFirstNameReqVal;
		protected System.Web.UI.WebControls.RegularExpressionValidator txtFirstNameRegexVal;
		protected System.Web.UI.WebControls.TextBox txtLastName;
		protected System.Web.UI.WebControls.RequiredFieldValidator txtLastNameReqVal;
		protected System.Web.UI.WebControls.RegularExpressionValidator txtLastNameRegexVal;
		protected System.Web.UI.WebControls.TextBox txtCity;
		protected System.Web.UI.WebControls.RegularExpressionValidator txtCityRegexVal;
		protected System.Web.UI.WebControls.RequiredFieldValidator txtCityReqVal;
		protected System.Web.UI.WebControls.ListBox lbStateProvince;
		protected System.Web.UI.WebControls.ListBox lbCountry;
		protected ActiveUp.WebControls.ActiveDateTime BirthDateSelector;
		protected System.Web.UI.WebControls.ListBox lbGender;
		protected System.Web.UI.WebControls.ListBox lbSecretWordType;
		protected System.Web.UI.WebControls.TextBox txtSecretWord;
		protected System.Web.UI.WebControls.RequiredFieldValidator txtSecretWordReqVal;
		protected System.Web.UI.WebControls.RegularExpressionValidator txtSecretWordRegexVal;
		protected System.Web.UI.WebControls.TextBox txtEmail;
		protected System.Web.UI.WebControls.RequiredFieldValidator txtEmailReqVal;
		protected System.Web.UI.WebControls.RegularExpressionValidator txtEmailRegexVal;
		protected System.Web.UI.WebControls.TextBox txtUserName;
		protected System.Web.UI.WebControls.RequiredFieldValidator usernameReqVal;
		protected System.Web.UI.WebControls.CustomValidator UserNameCheckDuplicateValue;
		protected System.Web.UI.WebControls.RegularExpressionValidator usernameRegexVal;
		protected System.Web.UI.WebControls.TextBox txtPassword;
		protected System.Web.UI.WebControls.RequiredFieldValidator txtpasswdReqVal;
		protected System.Web.UI.WebControls.RegularExpressionValidator txtpasswdRegexBal;
		protected System.Web.UI.WebControls.TextBox txtPassword2;
		protected System.Web.UI.WebControls.RequiredFieldValidator txtPassword2ReqVal;
		protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
		protected System.Web.UI.WebControls.TextBox txtHeadLine;
		protected System.Web.UI.HtmlControls.HtmlInputImage InputImage3;
		protected System.Web.UI.WebControls.Label BirthDate;
		protected MetaBuilders.WebControls.FirstFocus FirstFocus1;
		protected System.Web.UI.HtmlControls.HtmlForm Form1;
		// get Connection string from Config.web
		static string m_strConnection = System.Configuration.ConfigurationSettings.AppSettings["sRegistration_FormDBConnectionString"];	//	default connection string
		static SqlDataAdapter title;
		static string batchSQL = "Select * FROM titles; Select * FROM genders; Select * FROM secretwordtypes; Select * FROM states; Select * FROM countries";
		// create a SqlDataAdapter and use it to fill a DataSet SqlDataAdapter title; 
		public void txtUserName_TextChanged(object sender, System.EventArgs e)
		{
		}
		public void txtPassword_TextChanged(object sender, System.EventArgs e)
		{
		}
		public void txtPassword2_TextChanged(object sender, System.EventArgs e)
		{
		}
		public void txtFirstName_TextChanged(object sender, System.EventArgs e)
		{
		}
		public void txtLastName_TextChanged(object sender, System.EventArgs e)
		{
		}
		public void txtEmail_TextChanged(object sender, System.EventArgs e)
		{
		}
		public void lbTitle_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (null != lbTitle.SelectedItem)
			{
				Session["webform1_lbTitle"]=lbTitle.SelectedIndex; 
                //Session["webform1_lbTitle"] = lbTitle.SelectedValue;
			}
		}
		public void txtCity_TextChanged(object sender, EventArgs e)
		{
		}
		public void lbStateProvince_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (null != lbStateProvince.SelectedItem)
			{
				Session["webform1_lbStateProvince"]=lbStateProvince.SelectedIndex; 
				//Session["webform1_lbStateProvince"] = lbStateProvince.SelectedValue;
			}
		}
		public void lbCountry_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (null != lbCountry.SelectedItem)
			{
				Session["webform1_lbCountry"]=lbCountry.SelectedIndex; 
				//Session["webform1_lbCountry"] = lbCountry.SelectedValue;
			}
		}
		public void BirthDateSelector_DateChanged(object sender, ActiveUp.WebControls.DateChangedEventArgs e)
		{
			if (null != BirthDateSelector) 
			{
				Session["webform1_BirthDateSelector"] = BirthDateSelector;
			}
		}
		public void lbGender_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (null != lbGender.SelectedItem)
			{
				Session["webform1_lbGender"]= lbGender.SelectedIndex; 
				//Session["webform1_lbGender"] = lbGender.SelectedValue;
			}
		}
		public void lbSecretWordType_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (null != lbSecretWordType.SelectedItem)
			{
				Session["webform1_lbSecretWordType"]= lbSecretWordType.SelectedIndex;
				//Session["webform1_lbSecretWordType"] = lbSecretWordType.SelectedValue;
			}
		}
		public void txtSecretWord_TextChanged(object sender, EventArgs e)
		{
		}   
		public void txtHeadLine_TextChanged(object sender, System.EventArgs e)
		{
		}
		public void BindList(ref System.Web.UI.WebControls.ListBox MyList,
							 DataTable DataSource,
							 string ValueColumnName,
							 string TextColumnName
							 ) 
		{ 
			MyList.DataSource = DataSource; 
			MyList.DataTextField = TextColumnName; 
			MyList.DataValueField = ValueColumnName; 
			MyList.DataBind(); 
		} 
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!IsPostBack)
			{
				// Evals true first time browser hits the page
				DataSet ds = new DataSet(); 
				title = new SqlDataAdapter (batchSQL, m_strConnection); 
				title.Fill (ds);
				// Listbox for Title
				if  (Session["webform1_lbTitle"] == null)
				{
					BindList(ref lbTitle, ds.Tables[0], "title_id", "title_name"); 
				}
				else
				{
					string iSelected =  Session["webform1_lbTitle"].ToString(); 
				}
				// Listbox for Gender
				if  (Session["webform1_lbGender"] == null)
				{
					BindList(ref lbGender, ds.Tables[1], "gender_id", "gender_name"); 
				}
				else
				{
					string iSelected =  Session["webform1_lbGender"].ToString(); 
				}
				// Listbox for Secret Word
				if  (Session["webform1_lbSecretWordType"] == null)
				{
					BindList(ref lbSecretWordType, ds.Tables[2], "secretwordtype_id", "secretwordtype_name"); 
				}
				else
				{
					string iSelected =  Session["webform1_lbSecretWordType"].ToString(); 
				}
				// Listbox for State
				if  (Session["webform1_lbStateProvince"] == null)
				{
					BindList(ref lbStateProvince, ds.Tables[3], "state_id", "state_name"); 
				}
				else
				{
					string iSelected =  Session["webform1_lbStateProvince"].ToString(); 
				}
				// Listbox for Country 
				if  (Session["webform1_lbCountry"] == null)
				{
					BindList(ref lbCountry, ds.Tables[4], "country_id", "country_name"); 
				}
				else
				{
					string iSelected =  Session["webform1_lbCountry"].ToString(); 
				}
				if  (null != Session["webform1_txtUserName"])
				{ txtUserName.Text = Session["webform1_txtUserName"].ToString(); }
				if  (null != Session["webform1_txtPassword"])
				{ txtPassword.Text = Session["webform1_txtPassword"].ToString(); }
				if  (null != Session["webform1_txtPassword2"])
				{ txtPassword.Text = Session["webform1_txtPassword2"].ToString(); }
				if  (null != Session["webform1_txtFirstName"])
				{ txtFirstName.Text = Session["webform1_txtFirstName"].ToString(); }
				if  (null != Session["webform1_txtLastName"])
				{ txtLastName.Text = Session["webform1_txtLastName"].ToString(); }
				if  (null != Session["webform1_txtEmail"])
				{ txtEmail.Text = Session["webform1_txtEmail"].ToString(); };
				if  (null != Session["webform1_txtCity"])
				{ txtCity.Text = Session["webform1_txtCity"].ToString(); };
				if (null != Session["webform1_BirthDateSelector"])
				{ BirthDateSelector.Date = (System.DateTime)(Session["webform1_BirthDateSelector"]); };
				if  (null != Session["webform1_txtHeadLine"])
				{ txtHeadLine.Text = Session["webform1_txtHeadLine"].ToString(); }
				if  (null != Session["webform1_txtSecretWord"])
				{ txtSecretWord.Text = Session["webform1_txtSecretWord"].ToString(); };
			}	
		}
		// CODEGEN: This call is required by the ASP.NET Web Form Designer.
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			InitializeComponent();
			base.OnInit(e);
		}
		// <summary>
		// Required method for Designer support - do not modify
		// the contents of this method with the code editor.
		// </summary>
		private void InitializeComponent()
		{
			this.lbTitle.SelectedIndexChanged += new System.EventHandler(this.lbTitle_SelectedIndexChanged);
			this.txtFirstName.TextChanged += new System.EventHandler(this.txtFirstName_TextChanged);
			this.txtLastName.TextChanged += new System.EventHandler(this.txtLastName_TextChanged);
			this.lbStateProvince.SelectedIndexChanged += new System.EventHandler(this.lbStateProvince_SelectedIndexChanged);
			this.lbCountry.SelectedIndexChanged += new System.EventHandler(this.lbCountry_SelectedIndexChanged);
			this.lbGender.SelectedIndexChanged += new System.EventHandler(this.lbGender_SelectedIndexChanged);
			this.lbSecretWordType.SelectedIndexChanged += new System.EventHandler(this.lbSecretWordType_SelectedIndexChanged);
			this.txtPassword.TextChanged += new System.EventHandler(this.txtPassword_TextChanged);
			this.InputImage3.ServerClick += new System.Web.UI.ImageClickEventHandler(this.InputImage3_ServerClick);
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
		public void InputImage3_ServerClick(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if (Page.IsValid) 
			{
				Session["webform1_txtUserName"] = txtUserName.Text;
				Session["webform1_txtPassword"] = txtPassword.Text;
				Session["webform1_txtPassword2"] = txtPassword2.Text;
				Session["webform1_txtFirstName"] = txtFirstName.Text;
				Session["webform1_txtLastName"] = txtLastName.Text;
				Session["webform1_txtEmail"] = txtEmail.Text;
				Session["webform1_txtCity"] = txtCity.Text;
				Session["webform1_BirthDateSelector"] =  BirthDateSelector.Date;
				Session["webform1_txtHeadLine"] = txtHeadLine.Text;
				Session["webform1_txtSecretWord"] = txtSecretWord.Text;
				Server.Transfer("physicalcharacteristics.aspx", true);
			}
		}
	}
}
</code>

ok I understand?

Asked By matt cupryk on 03-Feb-04 01:41 AM
So I what am I missing?
<code>public void BindList(ref System.Web.UI.WebControls.ListBox MyList,
							 DataTable DataSource,
							 string ValueColumnName,
							 string TextColumnName
							 ) 
		{ 
			MyList.DataSource = DataSource; 
			MyList.DataTextField = TextColumnName; 
			MyList.DataValueField = ValueColumnName; 
			MyList.DataBind(); 
		} 
		public void RebindListBoxlbTitle ()
		{
			lbTitle.SelectedIndex= (int)Session["webform1_lbTitle"];
		}
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!IsPostBack)
			{
				// Evals true first time browser hits the page
				DataSet ds = new DataSet(); 
				title = new SqlDataAdapter (batchSQL, m_strConnection); 
				title.Fill (ds);
				// Listbox for Title
				if  (Session["webform1_lbTitle"] == null)
					BindList(ref lbTitle, ds.Tables[0], "title_id", "title_name"); 
				else
					RebindListBoxlbTitle(); 
				// Listbox for Gender
				if  (Session["webform1_lbGender"] == null)
					BindList(ref lbGender, ds.Tables[1], "gender_id", "gender_name"); 
				else
					RebindListBoxlbGender(); 
				// Listbox for Secret Word
				if  (Session["webform1_lbSecretWordType"] == null)
					BindList(ref lbSecretWordType, ds.Tables[2], "secretwordtype_id", "secretwordtype_name")
				else
					RebindListBoxllbSecretWordType(); 
				// Listbox for State
				if  (Session["webform1_lbStateProvince"] == null) 
					BindList(ref lbStateProvince, ds.Tables[3], "state_id", "state_name"); 
				else 
					RebindListBoxlbStateProvince(); 
				// Listbox for Country 
				if  (Session["webform1_lbCountry"] == null)
					BindList(ref lbCountry, ds.Tables[4], "country_id", "country_name"); 
				else 
					RebindListBoxlbStateProvince(); 
				if  (null != Session["webform1_txtUserName"]) 
					txtUserName.Text = Session["webform1_txtUserName"].ToString(); 
				if  (null != Session["webform1_txtPassword"]) 	
					txtPassword.Text = Session["webform1_txtPassword"].ToString(); 
				if  (null != Session["webform1_txtPassword2"])  
					txtPassword.Text = Session["webform1_txtPassword2"].ToString(); 
				if  (null != Session["webform1_txtFirstName"])  
					txtFirstName.Text = Session["webform1_txtFirstName"].ToString(); 
				if  (null != Session["webform1_txtLastName"]) 
					txtLastName.Text = Session["webform1_txtLastName"].ToString(); 
				if  (null != Session["webform1_txtEmail"]) 
					txtEmail.Text = Session["webform1_txtEmail"].ToString(); 
				if  (null != Session["webform1_txtCity"])
					txtCity.Text = Session["webform1_txtCity"].ToString(); 
				if (null != Session["webform1_BirthDateSelector"])
					BirthDateSelector.Date = (System.DateTime)(Session["webform1_BirthDateSelector"]); 
				if  (null != Session["webform1_txtHeadLine"]) 
					txtHeadLine.Text = Session["webform1_txtHeadLine"].ToString(); 
				if  (null != Session["webform1_txtSecretWord"])	
					txtSecretWord.Text = Session["webform1_txtSecretWord"].ToString(); 
			}	
		}</code>
OK Matt, we've gone along this
Asked By Peter Bromberg on 03-Feb-04 08:03 AM
thread several times. What you need to do now is figure out how to become an
independent coder and solve this problem by yourself.
If we keep holding your hand and writing your code for you at different forums, you will never get to the point where you are capable of delivering a finished product on your own. Good luck!