• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

is there a way to make the first index in a dropdown box clickable?

GoingUp

Lifer
I have a dropdown box that gets populated in .net. when the user changes the index, a query is run and the corresponding data for the order is shown.

here is the code for the dropdown box getting changed.

Private Sub ddorder_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddorder.SelectedIndexChanged


Try

Dim temp = ddorder.SelectedValue.ToString()
Convert.ToInt32(temp)

Dim Sql As String
Dim Cmd As OleDb.OleDbCommand

Dim Reader As OleDb.OleDbDataReader
Dim Con = New OleDb.OleDbConnection("SERVER INFO EDITED OUT")
' queries the database
Sql = "Select * from ORDERS WHERE Order_no = '" & temp & "'"
Cmd = New OleDb.OleDbCommand(Sql, Con)

Con.Open()

'converts the table to text
Reader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
If Reader.Read() Then
txtcustno.Text = Reader(0).ToString
txtfname.Text = Reader(1).ToString
txtlname.Text = Reader(2).ToString
txtcomp.Text = Reader(3).ToString
txtaddress.Text = Reader(4).ToString
txtcity.Text = Reader(5).ToString
txtstate.Text = Reader(6).ToString

End If ' end of reader loop
Con.Close()

Catch ex As Exception
lblstatus.Text = ex.Message
End Try
End Sub

Basically everything works fine, but the top result in the box cant be clicked on, unless another value is clicked on first. I could just stick this code somewhere else on the page to run when the box is filled initially, but i dont want to. Is there anyway that I can make the top item in the drop down box clickable the first time the user selects it?
 
Yep.. That would be the correct behaviour since that only fires when the index is changed, and initially by default it is 0, the first item. When you click it, no change there.

So what you need to do in your code is to put in a dummy value for the first index (0), which does nothing but maybe you can have it say "Choose Here" or something of that sort.
 
Just put "Select" or something as the first value. I haven't done this in .NET specifically, but it's what you have to do with javascript in non-.NET web development.
 
Back
Top