By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Listbox problem?

P: n/a
I have problems with listboxes in the webform2.cs, the textboxes are
working well when I do a click on next.
I am missing something. It works with the textboxes.
Here is the file:
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 WebForm2.
/// </summary>
public class WebForm2 : System.Web.UI.Page
{

// Declare field texbox names
protected System.Web.UI.HtmlControls.HtmlInputImage InputImage4;
protected System.Web.UI.HtmlControls.HtmlInputImage InputImage5;
protected System.Web.UI.WebControls.ListBox txtTitle;
protected System.Web.UI.WebControls.TextBox txtFirstName;
protected System.Web.UI.WebControls.TextBox txtLastName;
protected System.Web.UI.WebControls.ListBox txtGender;
protected System.Web.UI.WebControls.ListBox txtSecretWordType;
protected System.Web.UI.WebControls.TextBox txtSecretWord;
protected System.Web.UI.WebControls.TextBox txtCity;
protected System.Web.UI.WebControls.ListBox txtStateProvince;
protected System.Web.UI.WebControls.ListBox txtCountry;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

// Create a new DataSet for Title
//***********************************************
DataSet myDataSetTitle = new DataSet();
// Read XML file and populate tables

myDataSetTitle.ReadXml(Server.MapPath("GeneralInfo rmation/titles.xml"));
// Data bind ListBox the shortcut way
txtTitle.DataSource =
myDataSetTitle.Tables["title"].DefaultView;
txtTitle.DataBind();
// Create a new DataSet for Gender
//***********************************************
DataSet myDataSetGender = new DataSet();
// Read XML file and populate tables

myDataSetGender.ReadXml(Server.MapPath("GeneralInf ormation/genders.xml")
);
// Data bind ListBox the shortcut way
txtGender.DataSource =
myDataSetGender.Tables["gender"].DefaultView;
txtGender.DataBind();
// Create a new DataSet for SecretWordType
//***********************************************
DataSet myDataSetSecretWordType = new DataSet();
// Read XML file and populate tables

myDataSetSecretWordType.ReadXml(Server.MapPath("Ge neralInformation/Secre
tWordTypes.xml"));
// Data bind ListBox the shortcut way
txtSecretWordType.DataSource =
myDataSetSecretWordType.Tables["secretwordtype"].DefaultView;
txtSecretWordType.DataBind();
// Create a new DataSet for States/Provinces
//***********************************************
DataSet myDataSetStateProvince = new DataSet();
// Read XML file and populate tables

myDataSetStateProvince.ReadXml(Server.MapPath("Gen eralInformation/statep
rovinces.xml"));
// Data bind ListBox the shortcut way
txtStateProvince.DataSource =
myDataSetStateProvince.Tables["stateprovince"].DefaultView;
txtStateProvince.DataBind();
// Create a new DataSet for Countries
//***********************************************
DataSet myDataSetCountry = new DataSet();
// Read XML file and populate tables

myDataSetCountry.ReadXml(Server.MapPath("GeneralIn formation/countries.xm
l"));
// Data bind ListBox the shortcut way
txtCountry.DataSource =
myDataSetCountry.Tables["country"].DefaultView;
txtCountry.DataBind();

// Proccess values from Form1 and store them
if (!IsPostBack)
// Evals true first time browser hits the page
{

if (!(Session["webform2_txtTitle"] == null))
{ txtTitle.SelectedItem.Text =
Session["webform2_txtTitle"].ToString(); }
if (!(Session["webform2_txtFirstName"] == null))
{ txtFirstName.Text =
Session["webform2_txtFirstName"].ToString(); }
if (!(Session["webform2_txtLastName"] == null))
{ txtLastName.Text = Session["webform2_txtLastName"].ToString();
}
if (!(Session["webform2_txtGender"] == null))
{ txtGender.SelectedItem.Text =
Session["webform2_txtGender"].ToString(); };
if (!(Session["webform2_txtSecretWordType"] == null))
{ txtSecretWordType.SelectedItem.Text =
Session["webform2_txtSecretWordType"].ToString(); };
if (!(Session["webform2_txtSecretWord"] == null))
{ txtSecretWord.Text =
Session["webform2_txtSecretWord"].ToString(); };
if (!(Session["webform2_txtCity"] == null))
{ txtCity.Text = Session["webform2_txtCity"].ToString(); };
if (!(Session["webform2_txtStateProvince"] ==
null))
{ txtStateProvince.SelectedItem.Text =
Session["webform2_txtStateProvince"].ToString(); };
if (!(Session["webform2_txtCountry"] == null))
{ txtCountry.SelectedItem.Text =
Session["webform2_txtCountry"].ToString(); };

}

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
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.InputImage4.ServerClick += new
System.Web.UI.ImageClickEventHandler(this.InputIma ge4_Previous);
this.InputImage5.ServerClick += new
System.Web.UI.ImageClickEventHandler(this.InputIma ge5_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

public void InputImage4_Previous(object sender,
System.Web.UI.ImageClickEventArgs e)
{
Server.Transfer("webform1.aspx", true);
}

public void InputImage5_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
Response.Write ("Enter InputImage5_Click");

// Session["webform2_txtTitle"] = txtTitle.SelectedItem.Text;

Session["webform2_txtFirstName"] = txtFirstName.Text;

Session["webform2_txtLastName"] = txtLastName.Text;

// Session["webform2_txtGender"] = txtGender.SelectedItem.Text;

// Session["webform2_txtSecretWordType"] =
txtSecretWordType.SelectedItem.Text;

Session["webform2_txtSecretWord"] = txtSecretWord.Text;

Session["webform2_txtCity"] = txtCity.Text;

// Session["webform2_txtStateProvince"] =
txtStateProvince.SelectedItem.Text;

// Session["webform2_txtCountry"] = txtCountry.SelectedItem.Text;

Server.Transfer("webform3.aspx", true);

Response.Write ("Going to next page.");
}
}
}
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Mathieu,

|| I have problems with listboxes in the webform2.cs, the
|| textboxes are working well when I do a click on next.
|| I am missing something. It works with the textboxes.
|| Here is the file:

We're missing something too, I'm afraid. - Any clue as to what you're asking.

That's a lot of code you've given. Can you say anything specific about what the problem is. Anything about what you suspect is
wrong, etc, etc.

Simply saying that there's an error somewhere and giving a whole load of code is just making it harder to get a solution. You'll
need to find someone with the time and patience to examine all your code in detail. I have enough time to tell you this but not
enough to look at the code!

Sorry.

Regards,
Fergus
Nov 15 '05 #2

P: n/a

Given the following:
protected System.Web.UI.WebControls.DataList txtCountry;

How do I store the value in a session variable?

For example:
I am not sure with datalist.
Session["webform2_txtCountry"] = txtCountry.SelectedItem.Text;

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.