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

Creating a Web Interface in ASP.NET using C#

P: 34
Hi guys,

I posted a message before and I got some help from the forum. I have a database in SQL Server and I wanted to create a web interface in C#. I had 4 Listbox controls and a Textbox and two buttons for this. What I want to do is to select values from 4 Listbox controls and input some text in the textbox i.e year to display information on another page including all the information from $ listboxes too. I have no idea how to program this part. I have populated the 4 Listboxes from the database tables and I want to select some values from these listboxes and display information on another page. Could somebody help me in this regard. Below is the code I developed so far with your help.

protected void Page_Load(object sender, EventArgs e)
{
// create the connection string and command string

string connectionString = "Server=.\\SQLEXPRESS;Database=NorthWind;Integrate d Security=SSPI;";



string commandString = "Select * from Customers";
string commandString1 = "Select * from Orders";
string commandString2 = "Select * from Employees";
//pass the strings to the sql data adapter constructor

SqlDataAdapter dataAdapter = new SqlDataAdapter(commandString, connectionString);
SqlDataAdapter dataAdapter1 = new SqlDataAdapter(commandString1, connectionString);
SqlDataAdapter dataAdapter2 = new SqlDataAdapter(commandString2, connectionString);
SqlDataAdapter dataAdapter3 = new SqlDataAdapter(commandString2, connectionString);

// create a data set

DataSet dataSet = new DataSet();
// fill the dataset object

dataAdapter.Fill(dataSet, "Customers");
dataAdapter1.Fill(dataSet, "Orders");
dataAdapter2.Fill(dataSet, "Employees");
dataAdapter3.Fill(dataSet, "Products");






// for loop for customer table

foreach (DataRow dtrow in dataSet.Tables["Customers"].Rows)
{
ListBoxCustomers.Items.Add(dtrow["CustomerID"].ToString());
ListBoxCustomers.Items.Add(dtrow["City"].ToString());
ListBoxCustomers.Items.Add(dtrow["CompanyName"].ToString());
ListBoxCustomers.Items.Add(dtrow["ContactName"].ToString());
}


// for loop for Employees table

foreach (DataRow dtrow in dataSet.Tables["Employees"].Rows)
{
ListBoxEmployees.Items.Add(dtrow["EmployeeID"].ToString());
ListBoxEmployees.Items.Add(dtrow["LastName"].ToString());
ListBoxEmployees.Items.Add(dtrow["FirstName"].ToString());

}

// for loop for order table


foreach (DataRow dtrow in dataSet.Tables["Orders"].Rows)
{
ListBoxOrders.Items.Add(dtrow["OrderID"].ToString());
ListBoxOrders.Items.Add(dtrow["CustomerID"].ToString());
ListBoxOrders.Items.Add(dtrow["EmployeeID"].ToString());

}

And here is the Event Handler which I want to select values from the listboxes and a taxtbox and redirect the user to display relevant information on another page. Unfortunately I don't know how to code this part.

protected void BtnSubmit_Click(object sender, EventArgs e)
{

Response.Redirect("Default2.aspx"); // another page to display

}


I appreciate your help.

Koonda
Jan 14 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.