943,876 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 3745
  • VB.NET RSS
Apr 23rd, 2007
0

dropdownlist not firing

Expand Post »
what is wrong with my code?
VB.NET Syntax (Toggle Plain Text)
  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...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
shy_wani is offline Offline
34 posts
since Mar 2007
Apr 23rd, 2007
0

Re: dropdownlist not firing

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.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Apr 23rd, 2007
0

Re: dropdownlist not firing

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...
Reputation Points: 10
Solved Threads: 0
Light Poster
shy_wani is offline Offline
34 posts
since Mar 2007
Apr 23rd, 2007
0

Re: dropdownlist not firing

Quote ...
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.

Quote ...
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?
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Apr 23rd, 2007
0

Re: dropdownlist not firing

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?
Reputation Points: 10
Solved Threads: 0
Light Poster
shy_wani is offline Offline
34 posts
since Mar 2007
Apr 23rd, 2007
0

Re: dropdownlist not firing

ok...thanks hollystyles

now i've already got the solution...

i'm jumping all over my tv hall...yey!!!!
Reputation Points: 10
Solved Threads: 0
Light Poster
shy_wani is offline Offline
34 posts
since Mar 2007
Apr 23rd, 2007
0

Re: dropdownlist not firing

Thats it !

There you go, happy days.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Reverse a String
Next Thread in VB.NET Forum Timeline: printing current form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC