473,799 Members | 3,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to populate two dropdown list?when i select state city is automatically filled.

4 New Member
i have use this code when i select state city is automatically filled in 2nd dropdown according to the value of 1st dropdown.but it is not working.
Expand|Select|Wrap|Line Numbers
  1. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  2.     {
  3.         int countryid;
  4.         countryid = DropDownList1.SelectedIndex;
  5.         string cmdtxt = "select cid , [city_name] from city where sid=" + DropDownList1.SelectedIndex;
  6.         SqlDataAdapter da1 = new SqlDataAdapter(cmdtxt, connection.conn);
  7.         DataSet ds1 = new DataSet();
  8.         da1.Fill(ds1, "city");
  9.         ddlcity.DataSource = ds1.Tables["city"];
  10.         ddlcity.DataTextField = "statename";
  11.         ddlcity.DataValueField = "stateid";
  12.         ddlcity.DataBind();
  13.     }
Feb 11 '12 #1
3 2450
PsychoCoder
465 Recognized Expert Moderator Contributor
Before we go any further can you let us know what is going wrong, just saying it doesn't work isn't very helpful :)
Feb 11 '12 #2
rachna gandhi
4 New Member
it gives error like
Incorrect syntax near ','.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.Sql Client.SqlExcep tion: Incorrect syntax near ','.
Feb 15 '12 #3
MrMancunian
569 Recognized Expert Contributor
What happens if you put a breakpoint on
Expand|Select|Wrap|Line Numbers
  1. DataSet ds1 = new DataSet();
and evaluate cmdtxt on the line above it. Check if your query is correct. If you're not sure, paste it in your SQL Management Studio and see if it executes without a problem.
Feb 15 '12 #4

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

Similar topics

1
8295
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two dropdown lists. If you change the selection of the left one (e.g. choose parentoption2), it should open up page2.htm in a popup window.
2
30597
by: Manfred | last post by:
Hi I try to change the border of the <select> Tag to a thin, black line. On IE no reaction! <select style="border:1px solid #000000;background-color:red;"> <option>hallo</option> <option>hallo2</option> </select>
1
1320
by: dave | last post by:
Hello I have a pretty standard ASP.NET page where a user is required to enter their address. For the field "State", I am using a dropdown list of course. What is the best/easiest way to populate this control on a page load? I do not want to have to have a table in my data source that has all the US states. Is there a web server or something? Thanks, Dave
1
2014
by: Mark Goldin | last post by:
How can I populate a dropdownlist with data from a database using Microsoft.ApplicationBlocks.Data ? Thanks
3
4073
by: Merdaad | last post by:
I saw an example of this which talked about assigning valueTextField and DataTextField. So I have twenty items coming back from the database(I use a dataadapter), do I need to go thru a loop to assign each item in the Dropdown? Is there a way to just assign the datasource to a dataset (that's filled with data)? Thanks a lot Merdaad
3
3162
by: JIM.H. | last post by:
Hello, I am suing SELECT * from MyTable in a stored procedure and populate dropdown list. By using followings: ddlSP.DataSource = DS; ddlSP.DataTextField = "PName"; ddlSP.DataValueField = "PID"; ddlSP.DataBind(); This show PName in dropdown list, It is working fine. Now I need to combine PName, Field1 and Field2 as “PName: Field1 – Field2” and show it in the
1
1200
by: Johhn | last post by:
I am using VS 2005 and MS ACCESS database, i need to populate dropdown list box eith Items from row 1 to n and from x to y Any code samples? I am usig VB language. Thanks. Who gives me a solution will get a present from mee.
7
1719
by: arti | last post by:
In ASP.Net, I have a Dropdown List bound to a City Table with City Id as Value & City names as Data Text field. I want to Show a few Favourite Cities on top as well as in their correct place in the Dropdown List. Help!
0
2775
TonFrere
by: TonFrere | last post by:
Hello, I'm building a windows form application in Visual C# using VS 2005. On my form I need to populate a combobox with Invoices# linked to the current reccord's Order# value. This means that: - The combobox should repopulate if the user changes the value of Order#. - The combobox should repopulate if the user moves through records (using the binding navigator. My problem is that whenever I repopulate the combobox, it's value is reset to...
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10485
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10231
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9073
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.