Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 7th, 2006, 07:47 AM
Authorized User
 
Join Date: Jan 2006
Location: Hunza, Gilgit, Northern Areas, Pakistan.
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
  #2 (permalink)  
Old April 7th, 2006, 10:28 AM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
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

  #3 (permalink)  
Old April 8th, 2006, 05:59 AM
Authorized User
 
Join Date: Jan 2006
Location: Hunza, Gilgit, Northern Areas, Pakistan.
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

  #4 (permalink)  
Old April 10th, 2006, 01:26 AM
Registered User
 
Join Date: Nov 2005
Location: BANGKOK, , Thailand.
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.
  #5 (permalink)  
Old April 10th, 2006, 02:39 AM
Authorized User
 
Join Date: Jan 2006
Location: Hunza, Gilgit, Northern Areas, Pakistan.
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.
  #6 (permalink)  
Old April 12th, 2006, 02:37 AM
Authorized User
 
Join Date: Jan 2006
Location: Hunza, Gilgit, Northern Areas, Pakistan.
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

  #7 (permalink)  
Old April 12th, 2006, 02:38 AM
Authorized User
 
Join Date: Jan 2006
Location: Hunza, Gilgit, Northern Areas, Pakistan.
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

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:03 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.