Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 List Box Problem

Author  Topic 

vk18
Posting Yak Master

146 Posts

Posted - 2006-11-28 : 18:47:13
Hello Friends


I have a List Box and a Text Box on a form. I have 10 Items in the list box. 1 2 3 ...10. When i select the 10th item
in the List Box it is still displaying 1st item in the Text Box. Here is my code. can you guys tell me what i am doing wrong
Thx

This is the code for populating the selected item in the text box

Private Sub populatesubgrouptext(ByVal subgrouptext As String)
Dim sql As String
Dim dbfunctions As New DatabaseUtilities
Dim objdatarow As DataRow
Try
sql = "select description from tblsubgroups where ckid = '" & subgrouptext & "'"

objdatarow = dbfunctions.GetSQLDataRow(CONNECTIONSTRING, sql)

If objdatarow("description") Is DBNull.Value Then
Me.txtsubgroupdesc.Text = ""
Else
Me.txtsubgroupdesc.Text = objdatarow("description")
End If

Catch ex As Exception
End Try
End Sub

On Select Index changed i have this code

populatesubgrouptext(Me.lstsubgroup.SelectedValue)

Or is there any other way to display this data in the text box

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-29 : 01:49:00
Select Index Changed?
What happened to old fshioned Click event?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-11-29 : 09:04:58
You definitely want to use Index Changed, since not everyone is clicking the mouse.

Anyway, I'd set some break points and step through your code to ensure that things are executing properly, that's usually the best way to troubleshoot. It is hard to tell what is going on with just those small snippets of code.

Also, do not concatenate together SQL strings with input like that -- always use parameters!
see: http://weblogs.sqlteam.com/jeffs/archive/2006/07/21/10728.aspx


- Jeff
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-29 : 09:08:17
Click is fired even when changing rows with keyboard.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -