I am working in visual web developer and asp.net. as i am new to this program. pls help me out.
well, i tried to get my item on dropDownList1(College Name) and as i select one item from list1, corresponding list(Department) should be provided on dropDownList2. I got the item on first list, but could no manipulate it to get on the other. Pls tell me a way to do so. Its really urgent for me. please.
well, my first ddlist is dlCollege and second one is DlDept. so, i wrote the following code. but nothigns happend.
Protected Sub DlCollege_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DlCollege.SelectedIndexChanged
If DlCollege.Items.Item(0).Equals("Agriculture and Biological Sciences".ToString()) Then
DlDept.Items.Add("Ag Infor Tech Unit".ToString())
DlDept.Items.Add("Computer Unit".ToString())
DlDept.Items.Add("Research Lab".ToString())
DlDept.Items.Add("Agriculture purification".ToString())
DlDept.Items.Add("Main post info".ToString())
ElseIf DlCollege.Items.Item(1).Equals("Arts and Science".ToString()) Then
DlDept.Items.Add("Arts Tech Unit".ToString())
DlDept.Items.Add("Technical Department".ToString())
thanks for your suggestion. i hope you dont mind that i am quite novice in asp.net and stuffs. well, please tell me one thing. you know, i am using right now microsoft visual web developer to work with asp.net. and i have come to knwo that lots of ppl use visual studio.net 2003. so, please tell me what is the difference among these two.
wow, thanks for the suggestion. but well, it did not work fully again. the problem is that, when the page loads, first item in the first listbox is already selected, corresponding list does not show in the second list box.
Also, once, when second item in the first listbox is already selected, corresponding list show up in the second listbox, but when i select third item in the first list box, the second listbox does not get changed.!! My code is as follows: but then when i select one item in list1, items on list 2 keeps on adding over the previous one instead of displaying the new list for corresponding selection in list1.
While i add the items, is there some indexing i got to give for first list box??
If DlCollege.SelectedItem.ToString() = "Agriculture and Biological Sciences".ToString() Then
DlDept.Items.Add("Ag Infor Tech Unit".ToString())
DlDept.Items.Add("AgBio Communications Unit".ToString())
ElseIf DlCollege.SelectedItem.ToString() = "Arts and Science".ToString() Then
DlDept.Items.Add("AROTC".ToString())
DlDept.Items.Add("AFROTC".ToString())
ElseIf DlCollege.SelectedItem.ToString() = "Education and Counseling".ToString() Then
DlDept.Items.Add("Educational Leadership".ToString())
DlDept.Items.Add("CHRD".ToString())
ElseIf DlCollege.SelectedItem.ToString() = "Family and Consumer Sciences".ToString() Then
DlDept.Items.Add("AMID".ToString())
DlDept.Items.Add("HDCFS".ToString())
ElseIf DlCollege.SelectedItem.ToString() = "General Studies and Outreach Programs".ToString() Then
DlDept.Items.Add("".ToString())
ElseIf DlCollege.SelectedItem.ToString() = "Nursing".ToString() Then
DlDept.Items.Add("Graduate Nursing".ToString())
DlDept.Items.Add("Nursing Student Services".ToString())
ElseIf DlCollege.SelectedItem.ToString() = "Pharmacy".ToString() Then
DlDept.Items.Add("Pharmacy Practice".ToString())
DlDept.Items.Add("Pharmaceutical Sciences".ToString())
End If
End Sub
Please help me solve it!!
Last edited by ddl; 10-25-2006 at 10:14 AM.
Reason: Please review my code!!
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call DropDown()
End Sub
Private Sub DlCollege_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DlCollege.SelectedIndexChanged
Call DropDown()
End Sub
Public Sub DropDown()
DlDept.Items.Clear()
If DlCollege.SelectedItem.ToString() = "Agriculture and Biological Sciences".ToString() Then
DlDept.Items.Add("Ag Infor Tech Unit".ToString())
DlDept.Items.Add("AgBio Communications Unit".ToString())
ElseIf DlCollege.SelectedItem.ToString() = "Arts and Science".ToString() Then
DlDept.Items.Add("AROTC".ToString())
DlDept.Items.Add("AFROTC".ToString())
ElseIf DlCollege.SelectedItem.ToString() = "Education and Counseling".ToString() Then
DlDept.Items.Add("Educational Leadership".ToString())
DlDept.Items.Add("CHRD".ToString())
ElseIf DlCollege.SelectedItem.ToString() = "Family and Consumer Sciences".ToString() Then
DlDept.Items.Add("AMID".ToString())
DlDept.Items.Add("HDCFS".ToString())
ElseIf DlCollege.SelectedItem.ToString() = "General Studies and Outreach Programs".ToString() Then
DlDept.Items.Add("".ToString())
ElseIf DlCollege.SelectedItem.ToString() = "Nursing".ToString() Then
DlDept.Items.Add("Graduate Nursing".ToString())
DlDept.Items.Add("Nursing Student Services".ToString())
ElseIf DlCollege.SelectedItem.ToString() = "Pharmacy".ToString() Then
DlDept.Items.Add("Pharmacy Practice".ToString())
DlDept.Items.Add("Pharmaceutical Sciences".ToString())
End If
End Sub
Last edited by Chitra Xavier; 10-26-2006 at 12:22 AM.
Thank you so much..you've really been of great help. Thanks again. wow, i am happy that i can also work with asp!!hey man. got lot more to ask to you. dont feel bad bt it ha.
Thanks man!
well, on your given suggestion, i got the list of items on the second list according to selection on the first one. but the problem is that, if i select a new item from second list, the item being displayed on it does not get replaced.
Actually, now if i select any departments, then automatically respective department head's name and dept email address should pop in the two following ddlist boxes, namely dlDeptHead and dlDeptEmail.
well, i coded as below, but now it says, a debugging error as follows:
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.
Protected Sub DlDept_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DlDept.SelectedIndexChanged
DlDept.Items.Clear()
Call DropDownDlDeptHead()
End Sub
Public Sub DropDownDlDeptHead()
DlDeptHead.Items.Clear()
If DlDept.SelectedItem.ToString() = "Ag Infor Tech Unit".ToString() Then
DlDeptHead.Items.Add("Dr. Thomas Gerudn".ToString())
DlDeptEmail.Items.Add("thomas.gerudn@hotmail.com".ToString())
ElseIf DlDept.SelectedItem.ToString() = "AgBio Communications Unit".ToString() Then
DlDeptHead.Items.Add("Ms. Barb Hartinger".ToString())
To avoid error give "AutoPostBack" property "True" for all the DropDowns u use.
Its always safe to use database,since the program we do should be adaptive for future changes.Hard coding limits the usage of a program.Always code generic.
what i tried to do is, when i have item selected in DlList1, DlList 2 and DlList3 should be filled in with respective values. but, the way i am doin is not correct. it works when i only gice DlList2. but when i add the second line after first line, the if statement seems not to work.
If DlList3 is DropDownList control then "Text.Insert" is not an property of dropdown.
Also check the Id value of DlList3 with the given above code.I think they differ.
thanks..
it worked!!
ya, that was my mistake. it did work this way!!
If DlDept.SelectedItem.ToString() = "Ag Infor Tech Unit".ToString() Then
dlDeptHead.Items.Add("Dr. Mike Adelaine".ToString())
DlDeptEmail.Text = "Michael.Adelaine@SDSTATE.EDU".ToString()
well, chitra, right now, as i was working, all of a sudden, an error poped in saying:
Failed to generate a user instance of SQL Server due to a failure in starting the process for the uer instance. The connection will be closed.
could you please tell me what is it?
Thanks,..
hope i am not goin to give you a burden to send the entire project over mail and tell,, hey chitra, could you pls see............and then....i am done with my final project!!
Bookmarks