|
 |
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 .
|
 |
|
|

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
|
|
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
|

April 7th, 2006, 10:28 AM
|
Friend of Wrox
|
|
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
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
|

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
|
|
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
|
|

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
|
|
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.
|

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
|
|
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.
|
|

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
|
|
Thanks all for you replies........
The Problem has been sorted out.....when i added if(!Page.IsPostBack) in my page-load
Bbye
A-Ghaffar
|

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
|
|
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 |
|
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |