-
VB.NET (
http://www.daniweb.com/forums/forum58.html)
| shy_wani | Apr 23rd, 2007 1:17 am | |
| dropdownlist not firing what is wrong with my code?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyConnection.Open()
Dim strSQL As String = "SELECT * FROM Question WHERE SurveyID=83 Order By QuestionNum"
Dim cnCommand1 As SqlCommand = New SqlCommand(strSQL, MyConnection)
Dim Rdr As SqlDataReader = cnCommand1.ExecuteReader() 'execute reader to catch data from db to drop dwon lists
With qnum
.DataSource = Rdr
.DataValueField = "QuestionID"
.DataTextField = "QuestionNum"
.DataBind()
End With
'Rdr.NextResult()
'With lstOptions
' .DataSource = Rdr
' .DataValueField = "OptionID"
' .DataTextField = "OptionList"
' .DataBind()
'End With
'close the reader
Rdr.Close()
End Sub
Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim questid As String = qnum.SelectedItem.Value
For Each s As String In questid
Dim sql As String = "SELECT * From AnswerList WHERE SurveyID=83 AND QuestionID='" & questid & "' Order By QuestionNum"
Dim cmd As SqlCommand = New SqlCommand(sql, MyConnection)
Dim reader As SqlDataReader
reader = cmd.ExecuteReader
With lstOptions
.DataSource = reader
.DataValueField = "OptionID"
.DataTextField = "OptionList"
.DataBind()
End With
reader.Close()
Next
'Close the DB Connection
MyConnection.Close()
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... |
| hollystyles | Apr 23rd, 2007 5:02 am | |
| 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. |
| shy_wani | Apr 23rd, 2007 5:42 am | |
| Re: dropdownlist not firing Quote: Originally Posted by hollystyles (Post 350691) 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... |
| hollystyles | Apr 23rd, 2007 6:22 am | |
| 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? |
| shy_wani | Apr 23rd, 2007 7:02 am | |
| 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?
<asp:Dropdownlist id=qnum runat="server" DataValueField="QuestionID" DataTextField="QuestionNum" OnSelectedIndexChanged="populateOption()"/>
then at
sub populateOption(......)
--generate OptionList to lstOptions----
am i right until here? |
| shy_wani | Apr 23rd, 2007 8:46 am | |
| Re: dropdownlist not firing ok...thanks hollystyles
now i've already got the solution...
i'm jumping all over my tv hall...yey!!!! |
| hollystyles | Apr 23rd, 2007 8:53 am | |
| Re: dropdownlist not firing Thats it !
There you go, happy days.:cool: |
| All times are GMT -4. The time now is 11:49 pm. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC