About Syed Adeel Rizvi Expertise I can answers questions regarding web based and desktop based programming in VB.Net. Which can include XML, Custom Controls + Computer Hardware and Windows Turboshooting...etc.
More Skills :
1 . PHP - > All Type Of CMS e.g. (Joomla,Drupul,PHPNuke...etc)
2 . ASP
3 . ASP.Net
4 . CMS
5 . MySql
6 . SQl Server 2000 & 2005
7 . Ms Access
8 . Web Designing
9 . Networking Turboshooting
10 . Windows Turboshooting
11 . Hardware Turboshooting
All Type Of Work Related To IT
I also Do Work as a Freelance as Application & Web Developer & Designer
Experience i have 3 years work experience in software house and 4 years work experience for computer hardware and Networking..
Expert: Syed Adeel Rizvi Date: 7/19/2007 Subject: Select item from a drop down list
Question Hi,
I am writing a program in vs2005 using vb.net. My problem lies in the area where I have two drop down lists called "cadre" and "grade". The grade populates depending on the value of cadre. All the values come from the database. A table in the database has columns cadre and grade and cadre repeats for all different values of grade. For instance, if I have 4 grades for cadre 1, then in the cadre column cadre 1 will repeat 4 times, each having a unique grade value.
To populate the grade ddl, I initially tried to do this:
Dim cmd12 As New SqlCommand("SELECT Cgrade from access_control.dbo.table_cadre" & _
" WHERE cadre = '" & ddl_cadre.SelectedItem.Text & "' ", consql)
This generated an error "Object reference not set to an instance of an object." So I tried to figure out ddl_cadre.SelectedItem.Text actually displays a value. I said
txt_box.text = ddl_cadre.SelectedItem.Text
I first put this code in SelectedIndexchanged function and it didn't do anything. Then I placed it in a button and the text would only be the very first value in the cadre list (which is "SELECT" and it isnt really a value).
To make sure that the problem is not with SELECT not being a choice in the cadre database, I added SELECT and some random value for grade by it. I still got the same error.
So, I am not sure exactly where the real problem lies but it looks like ddl_cadre.SelectedItem.Text doesn't give the right value. Moreover, just by choosing an option in the cadre box, the text doesn't appear in a text box, I have to hit a button for it.
In short, I want to be able to select the right choice from the cadre box and also automatically populate the grade box based on the selection. I appreciate your assistance.
Thanks,
Fauzia
Answer Hello
So i simple words you want to pass the value from ddl to SQL query hmm ok...
here :
Your code...
Dim cmd12 As New SqlCommand("SELECT Cgrade from access_control.dbo.table_cadre" & _
" WHERE cadre = '" & ddl_cadre.SelectedItem.Text & "' ", consql)