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.
Author |
Topic |
Sirchrisak
Starting Member
19 Posts |
Posted - 2005-06-13 : 11:29:00
|
I am Adding Some Item From DataGrid Control to ListBox. I Need To Check that The item I am about to Add does not exist in the listBox. I have done this Kind of thing with VB.Net But that code can't work In ASP.NetThis is my code, [CODE]Dim Str As String = DataGrid2.DataKeys(e.Item.ItemIndex) If Not ListFirst.Items.Contains(Str) Then ListFirst.Items.Add(Str) End If[/CODE] my Problem is that variable "Str" is underlined with blue Line with a message that "string cannot be converted to System.UI.webcontrols.ListItem "Please help outThanksChris |
|
jhermiz
3564 Posts |
Posted - 2005-06-13 : 11:58:15
|
[code] Private Sub ibAddItem_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibAddItem.Click 'add highlighted wbs elements into selected list box Dim i As Integer If Me.lbAvailable.Items.Count > 0 Then For i = 0 To Me.lbAvailable.Items.Count - 1 If Me.lbAvailable.Items(i).Selected = True Then 'check it first If Not CheckAlreadySelected(Me.lbAvailable.Items(i).Text) Then 'add it Dim l As New ListItem(Me.lbAvailable.Items(i).Text, Me.lbAvailable.Items(i).Value) Me.lbSelected.Items.Add(l) Else 'don't add it End If End If Next 'clear the highlighted from the available list box ClearAvailableEmails() Else 'do nothing End If End Sub[/code]And...[code] Private Function CheckAlreadySelected(ByVal strEmail As String) As Boolean Dim i As Integer If Me.lbSelected.Items.Count > 0 Then For i = Me.lbSelected.Items.Count - 1 To 0 Step -1 If Me.lbSelected.Items(i).Text = strEmail Then CheckAlreadySelected = True Exit Function End If Next End If CheckAlreadySelected = False End Function[/code] Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]Imperfection living for perfection -- [url]http://jhermiz.blogspot.com/[/url] |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-06-13 : 12:35:24
|
Use the FindByText() method of a ListBox instead of Contains() if you want to search for a particular string.- Jeff |
 |
|
|
|
|