Selecting multiple rows from a list box

Results 1 to 2 of 2

Thread: Selecting multiple rows from a list box

  1. #1
    Join Date
    Dec 1969

    Default Selecting multiple rows from a list box

    Hello,<BR><BR>Can you please help me with this code, I&#039;m converting from VB6 to ASP.NET. Errors: ListBox1.ListCount, Right(ListBox1.List(w), 2).<BR><BR>For w = 0 To (ListBox1.ListCount - 1)<BR> If ListBox1.Selected(w) Then<BR> If Len(s) &#062; 0 Then<BR> s = s & "AND CTRYX LIKE " & "&#039;*" & Right(ListBox1.List(w), 2) & "*&#039;"<BR> Else<BR> s = "&#039;*" & Right(ListBox1.List(w), 2) & "*&#039;"<BR> End If<BR> End If<BR> Next<BR><BR>Thanks

  2. #2
    Join Date
    Dec 1969

    Default RE: Selecting multiple rows from a list box

    There&#039;s obviously about a zillion ways to write it, but I&#039;d go for something like this:<BR><BR>Dim i As Integer<BR>Dim whereClause As String = String.Empty<BR>Dim sql As String = "SELECT * FROM Employees"<BR><BR>&#039; because we used a Checkbox *LIST* control we have access<BR>&#039; to it&#039;s collection of Items. No need to enumerate every<BR>&#039; control on the page...<BR>For i = 0 To myCheckBoxList.Items.Count - 1<BR>*** If myCheckBoxList.Items(i).Selected Then<BR>******* &#039; get the value of this item<BR>******* Dim tmpStrng As String = myCheckBoxList.Items(i).Text<BR>******* &#039; get the last two chars<BR>******* tmpStrng = tmpStrng.Substring(tmpStrng.Length - 3)<BR>******* &#039; Use ternary IIf function - must call toString because IIf returns<BR>******* &#039; object Type<BR>******* whereClause &amp;= IIf(whereClause Is String.Empty, _<BR>*********** " WHERE CTRYX LIKE &#039;%" &amp; tmpStrng &amp; "%&#039;", _<BR>*********** " AND CTRYX LIKE &#039;%" &amp; tmpStrng &amp; "%&#039;").ToString()<BR>*** End If<BR>Next<BR><BR>&#039; append the where clause if relevant<BR>If (whereClause.Length &gt; 0) Then<BR>*** sql &amp;= whereClause<BR>End If<BR><BR>&#039; Display the sql...<BR>Response.Write(sql)<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts