Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 7th, 2006, 07:47 AM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hunzian78@yahoo.com
Default TWO DROPDOWNLISTS POPULATED FROM DATABASE

HI ALL....

FRANKLY FIRST OF ALL I WANT TO TELL YOU THAT FOR LAST ONE WEEK I HAVE BEEN STUCKED WITH THE TWO DROPDOWN LISTs.......SERARCHED THE NET SO THROUGHLY BUT COULDN'T FIND ANY SOLUTION.........I HOPE ANY OF YOU MUST HAVE THE SOLUTION. THE PROBLEM IS..

I HAVE TWO DROPDOWNLISTS, ONE FOR THE COUNTRY AND THE OTHER FOR CITY. I AM ABLE TO POPULATE THE COUNTRY's DROPDOWNLIST FROM THE ACCESS DATABASE AND ALSO ABLE TO POPULATE THE CITY DROPDOWN LIST ON BEHALF OF THE FIRST SELECTED COUNTRY FROM COUNTRY'S DROPDOWNLIST USING THE SELECTEDINDEXCHAGED EVENT. BUT I AM NOT ABLE TO POPULATE THE OTHER COUNTRY'S CITY IN CITY DROPDOWNLIST, WHEN I CLICK THE SECOND COUNTRY IN COUNTRY'S DROPDOWNLIST, HOW CAN IT BE....

THE BROWSER DOESN'T THROUWS AN ERROR, BUT WHEN I SELECT THE SECOND COUNTRY , AFTER POSTBACK THE FIRST COUNTRY REMAINS HIGHLITED INSTEAD OF THE SECOND COUNTRY WHICH HAD BEEN CLICKED.

THE FOLLOWING IS THE CODE WHICH I AM EXECUTING:

private void Page_Load(object sender, System.EventArgs e)
{
string str;
str = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\dropdown1\database\users .mdb;Persist Security Info=False";
OleDbConnection strConnection = new OleDbConnection(str);
strConnection.Open();
OleDbCommand objCommand = new OleDbCommand("Select country from country", strConnection);
OleDbDataReader dr;
dr = objCommand.ExecuteReader();

DropDownList1.DataSource = dr;
DropDownList1.DataBind();


strConnection.Close();
}

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{

string str;
str = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\dropdown1\database\users .mdb;Persist Security Info=False";
OleDbConnection strConnection = new OleDbConnection(str);
strConnection.Open();
OleDbCommand objCommand = new OleDbCommand("SELECT city FROM city where country='" + DropDownList1.SelectedItem.Text + "' " , strConnection);
OleDbDataReader dr;
dr = objCommand.ExecuteReader();


DropDownList2.DataSource = dr;
DropDownList2.DataBind();

strConnection.Close();

}

I HAVE USED THE DataTextField = " country " for first dropdownlist and DataTextField = " city " for the second dropdownlist in .aspx file.


Thank you in anticipation in advance for your reply...


Abdul Ghaffar
 
Old April 7th, 2006, 10:28 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Hi,

I'm using double drop-down lists all throughout my application. I'm not really all that familiar with C# but in VB syntax I have to add the 'Handles' syntax for it to fire off and fill the second drop-down otherwise changing the selectedindex change for the first drop-down does nothing. I don't know if the syntax for C# is the same but I'm guessing there might be some kind of similar functionality. Also when declaring the variables they must be declared using WithEvents.

Private Sub ddlAreaID_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlAreaID.SelectedIndexChanged

 
Old April 8th, 2006, 05:59 AM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hunzian78@yahoo.com
Default


Hi...thanks for your reply.....but i don't have any idea about Handles in C#......

Abdul Ghaffar



Quote:
quote:Originally posted by rstelma
 Hi,

I'm using double drop-down lists all throughout my application. I'm not really all that familiar with C# but in VB syntax I have to add the 'Handles' syntax for it to fire off and fill the second drop-down otherwise changing the selectedindex change for the first drop-down does nothing. I don't know if the syntax for C# is the same but I'm guessing there might be some kind of similar functionality. Also when declaring the variables they must be declared using WithEvents.

Private Sub ddlAreaID_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlAreaID.SelectedIndexChanged

 
Old April 10th, 2006, 01:26 AM
Registered User
 
Join Date: Nov 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tanakrita Send a message via Yahoo to tanakrita
Default

Hello,

Pls check whether in DDL (Country)'s Autopostback property is set to 'True'. If it is false, your code may not work.



Tanakrit A.
 
Old April 10th, 2006, 02:39 AM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hunzian78@yahoo.com
Default

Thanks Tanakrit A. for your reply.......

The DropdownList autopost back propery is already set to 'true'.

Abdul Ghaffar

Quote:
quote:Originally posted by tanakrita
 Hello,

Pls check whether in DDL (Country)'s Autopostback property is set to 'True'. If it is false, your code may not work.



Tanakrit A.
 
Old April 12th, 2006, 02:37 AM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hunzian78@yahoo.com
Default

Thanks all for you replies........

The Problem has been sorted out.....when i added if(!Page.IsPostBack) in my page-load

Bbye
A-Ghaffar

 
Old April 12th, 2006, 02:38 AM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hunzian78@yahoo.com
Default

Thanks all for you replies........

The Problem has been sorted out.....when i added if(!IsPostBack)

in my page-load

Bbye
A-Ghaffar






Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo Box Populated off Database Firehawk2006 Visual Basic 2005 Basics 1 November 28th, 2005 01:47 PM
DropDownLists venterjo General .NET 1 January 8th, 2005 09:10 AM
Value not being populated in Text Box ashu_gupta75 Classic ASP Basics 2 April 19th, 2004 11:21 PM
Populated dropdown and database kecik101 Classic ASP Basics 2 April 16th, 2004 10:24 PM
how to keep data first populated to user control alyeng2000 ASP.NET 1.0 and 1.1 Professional 6 December 13th, 2003 06:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.