473,396 Members | 1,809 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.

DropDown List help

Hey guys!
I wrote a script with 2 dropdown lists. When the value on one is
selected it should automatically load the corresponding value from the table
on the second list. This for some apparent reason is not working.

Label1.Text=this.ddList1.SelectedItem.ToString();
SqlCommand sqlCmd2 =new SqlCommand("SELECT Name FROM pricesTB1 WHERE
Location="+Label1.Text,conn);
conn.Open();
SqlDataReader read2=sqlCmd2.ExecuteReader();
while (read2.Read())
{
//ListItem NewItem2 = new ListItem();
//NewItem2.Text=read2.GetString(0);
//NewItem2.Value = read2.GetValue(0).ToString();
//ddList2.Items.Add(NewItem2);
Label2.Text=this.ddList1.SelectedItem.ToString();
}
conn.Close();

It works fine when i explicitely define the SQL Command but when i read it
using this.ddList1.SelectedItem.ToString();
it messes up...Please help me.
Thanks
Nov 16 '05 #1
3 1079
here is how i am using it in my app and its working fine
=================================================
dataSet2.Clear();

comboBox2.Items.Clear();

this.oleDbSelectCommand2.CommandText = "SELECT Distinct khewatnum FROM
khewat WHERE (mahal = ?)";

this.oleDbSelectCommand2.Connection = this.oleDbConnection1;

this.oleDbSelectCommand2.Parameters.Add(new
System.Data.OleDb.OleDbParameter("mahal",comboBox1 .SelectedItem.ToString()))
;

this.oleDbDataAdapter2.Fill(dataSet2 , "mydata2");

for (int i = 0 ; i < dataSet2.Tables["mydata2"].Rows.Count ; i ++ )

{

comboBox2.Items.Add(dataSet2.Tables["mydata2"].Rows[i].ItemArray.GetValue(0)
);

}

this.oleDbSelectCommand2.Parameters.Clear();

================================================== ==========================
==============

"Dharmen" <as**@asas.com> wrote in message
news:ea**************@TK2MSFTNGP11.phx.gbl...
Hey guys!
I wrote a script with 2 dropdown lists. When the value on one is
selected it should automatically load the corresponding value from the table on the second list. This for some apparent reason is not working.

Label1.Text=this.ddList1.SelectedItem.ToString();
SqlCommand sqlCmd2 =new SqlCommand("SELECT Name FROM pricesTB1 WHERE
Location="+Label1.Text,conn);
conn.Open();
SqlDataReader read2=sqlCmd2.ExecuteReader();
while (read2.Read())
{
//ListItem NewItem2 = new ListItem();
//NewItem2.Text=read2.GetString(0);
//NewItem2.Value = read2.GetValue(0).ToString();
//ddList2.Items.Add(NewItem2);
Label2.Text=this.ddList1.SelectedItem.ToString();
}
conn.Close();

It works fine when i explicitely define the SQL Command but when i read it
using this.ddList1.SelectedItem.ToString();
it messes up...Please help me.
Thanks

Nov 16 '05 #2
Try this.ddList1.SelectedItem.Text
Nov 16 '05 #3
Hey Guys...Thanks for the replies!
I still have problems but this time atleast it doesnt gimme any errors...It
jist doesnt enter the while (read2.Read())
loop! I think this is because Im usign sqlCmd.Execute Reader in the first
function and the sqlCmd2.ExecuteReader again.

Is this wrong? or do i have to do anything to close it? I need help in C#
please...i dont know much of VB...If u have MSN ID it would be helpful!
Thanks!

"Dharmen" <as**@asas.com> wrote in message
news:ea**************@TK2MSFTNGP11.phx.gbl...
Hey guys!
I wrote a script with 2 dropdown lists. When the value on one is
selected it should automatically load the corresponding value from the table on the second list. This for some apparent reason is not working.

Label1.Text=this.ddList1.SelectedItem.ToString();
SqlCommand sqlCmd2 =new SqlCommand("SELECT Name FROM pricesTB1 WHERE
Location="+Label1.Text,conn);
conn.Open();
SqlDataReader read2=sqlCmd2.ExecuteReader();
while (read2.Read())
{
//ListItem NewItem2 = new ListItem();
//NewItem2.Text=read2.GetString(0);
//NewItem2.Value = read2.GetValue(0).ToString();
//ddList2.Items.Add(NewItem2);
Label2.Text=this.ddList1.SelectedItem.ToString();
}
conn.Close();

It works fine when i explicitely define the SQL Command but when i read it
using this.ddList1.SelectedItem.ToString();
it messes up...Please help me.
Thanks

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

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...
1
by: news | last post by:
Hello, I need help with the following problem: An HTML page that have two dropdown list whit different values: 1. Dropdown list 1(tblname1) =values with different location's. After user...
6
by: San Smith | last post by:
I have a dropdown list box with list of item. When I read the data from database I want to display that value(one of the item in the drop down box) in the dropdown list box. How to do that in a...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: Kay | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
0
by: Kay O'Keeffe | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
3
by: er1 | last post by:
Hi all, I have created a double dropdown list. Based on the first list selection, second list populates (this works fine). I have a submit button, which when clicked should run a select query...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
3
by: fish919 | last post by:
Hello All, I am creating a date base in access. I want to create a dropdown list box that is connected to another dropdown list box. You start with a dropdown list that has 5 choices and each of...
4
by: Paul | last post by:
Hi all, I have a page that has a form on it which has a dropdown list on it. It connect to an sql database and populate the list. What I would like to do is make the list editable so that if the...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.