dropdownlist not firing

Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Mar 2007
Posts: 34
Reputation: shy_wani is an unknown quantity at this point 
Solved Threads: 0
shy_wani shy_wani is offline Offline
Light Poster

dropdownlist not firing

 
0
  #1
Apr 23rd, 2007
what is wrong with my code?
  1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.  
  3. MyConnection.Open()
  4. Dim strSQL As String = "SELECT * FROM Question WHERE SurveyID=83 Order By QuestionNum"
  5. Dim cnCommand1 As SqlCommand = New SqlCommand(strSQL, MyConnection)
  6. Dim Rdr As SqlDataReader = cnCommand1.ExecuteReader() 'execute reader to catch data from db to drop dwon lists
  7.  
  8. With qnum
  9. .DataSource = Rdr
  10. .DataValueField = "QuestionID"
  11. .DataTextField = "QuestionNum"
  12. .DataBind()
  13. End With
  14.  
  15. 'Rdr.NextResult()
  16. 'With lstOptions
  17. ' .DataSource = Rdr
  18. ' .DataValueField = "OptionID"
  19. ' .DataTextField = "OptionList"
  20. ' .DataBind()
  21. 'End With
  22. 'close the reader
  23. Rdr.Close()
  24.  
  25.  
  26.  
  27. End Sub
  28.  
  29. Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
  30. Dim questid As String = qnum.SelectedItem.Value
  31. For Each s As String In questid
  32. Dim sql As String = "SELECT * From AnswerList WHERE SurveyID=83 AND QuestionID='" & questid & "' Order By QuestionNum"
  33. Dim cmd As SqlCommand = New SqlCommand(sql, MyConnection)
  34. Dim reader As SqlDataReader
  35. reader = cmd.ExecuteReader
  36.  
  37. With lstOptions
  38. .DataSource = reader
  39. .DataValueField = "OptionID"
  40. .DataTextField = "OptionList"
  41. .DataBind()
  42. End With
  43.  
  44. reader.Close()
  45.  
  46. Next
  47.  
  48. 'Close the DB Connection
  49. MyConnection.Close()
  50. End Sub

i want to populate the lstOptions (a listbox) based on the item selected in frop down list named "qnum"

the problem is..the data in lstOptions changed only at first time the dropdown list value change...the 2nd,3rd change of the dropdownlist, the lstOptions value doesn't change

plzz help me...
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: dropdownlist not firing

 
0
  #2
Apr 23rd, 2007
The code you post has no handler for the SelectedIndexChange event of your drop down control, instead you have a button click handler. So to cause the List box to be rebound, in your programs current state, you need to make a selection in the drop down and then click the submit button every time to get a change in the list box.
Last edited by hollystyles; Apr 23rd, 2007 at 5:02 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 34
Reputation: shy_wani is an unknown quantity at this point 
Solved Threads: 0
shy_wani shy_wani is offline Offline
Light Poster

Re: dropdownlist not firing

 
0
  #3
Apr 23rd, 2007
Originally Posted by hollystyles View Post
The code you post has no handler for the SelectedIndexChange event of your drop down control, instead you have a button click handler. So to cause the List box to be rebound, in your programs current state, you need to make a selection in the drop down and then click the submit button every time to get a change in the list box.
can u elaborate more? i can't figured out where to add the handler? does it mean that i don't need a button click handler?
hope u can help me....your help is very much appreciated...
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: dropdownlist not firing

 
0
  #4
Apr 23rd, 2007
can u elaborate more? i can't figured out where to add the handler?
Same place you have the button click handler. You have managed to create a click event handler for your button, making a SelectedIndexChange handler for your drop down list is no different.

does it mean that i don't need a button click handler?
That's up to you and your design. Do you want the user to have to click a button after selecting a question? or do you want their selection to be actioned immediately they select it in the drop down control?
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 34
Reputation: shy_wani is an unknown quantity at this point 
Solved Threads: 0
shy_wani shy_wani is offline Offline
Light Poster

Re: dropdownlist not firing

 
0
  #5
Apr 23rd, 2007
ok..
i made up my mind that their selection to be actioned immediately they select it in the drop down control...
if so, then i don't need the button right?
so..does it mean that i should add SelectedIndexChanged into my drop down control?

<aspropdownlist id=qnum runat="server" DataValueField="QuestionID" DataTextField="QuestionNum" OnSelectedIndexChanged="populateOption()"/>

then at
sub populateOption(......)
--generate OptionList to lstOptions----

am i right until here?
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 34
Reputation: shy_wani is an unknown quantity at this point 
Solved Threads: 0
shy_wani shy_wani is offline Offline
Light Poster

Re: dropdownlist not firing

 
0
  #6
Apr 23rd, 2007
ok...thanks hollystyles

now i've already got the solution...

i'm jumping all over my tv hall...yey!!!!
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: dropdownlist not firing

 
0
  #7
Apr 23rd, 2007
Thats it !

There you go, happy days.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC