473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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 2442
PsychoCoder
465 Expert Mod 256MB
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
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.SqlClient.SqlException: Incorrect syntax near ','.
Feb 15 '12 #3
MrMancunian
569 Expert 512MB
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
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...
2
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>...
1
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...
1
by: Mark Goldin | last post by:
How can I populate a dropdownlist with data from a database using Microsoft.ApplicationBlocks.Data ? Thanks
3
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...
3
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";...
1
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...
7
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...
0
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: -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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 project—planning, coding, testing,...

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.