Home » Asp.netRSS

How do you concatenate using LINQ?

Hello,

I would like to select multiple rows in a grid and concatenate my query with the "or" statement, however the code below doesn't work, any ideas what's is wrong with it?

Code:

Dim vc1 As Integer

For Each row As GridViewRow In GridView2.Rows

'Find checkbox in the row

Dim chb As CheckBox = DirectCast(row.FindControl("CheckBox1"), CheckBox)

'if checkbox is found and is checked then add the id to string

If chb IsNot Nothing AndAlso chb.Checked Then

If vc1 > 0 Then

yx = yx Or ListBox1.SelectedValue.ToString ****Error Line

Else

yx = "" & row.Cells(1).Text & ""

End If

vc1 = vc1 + 1

End If

Next

Thanks,

Victor

 

3 Answers Found

 

Answer 1

Hi,

To do this loop the each row  and find  the row which has selected checkbox.


 

Answer 2

Hello,

when the user clicks on more than one checkbox, I am trying to create the following string  for yx:

Receiver like "1" or reciver like "2" or receiver like "3", when I click three check boxes on the grid,

the code  below unfortunately doesn't work, can you please help me with the proper code.

Thanks,

Victor

Dim vc1 As Integer

For Each row  As GridViewRow In GridView2.Rows

'Find checkbox  in the row

Dim chb As CheckBox = DirectCast(row.FindControl("CheckBox1"), CheckBox)

'if checkbox is found  and is checked  then add  the id to string

If chb IsNot Nothing AndAlso chb.Checked Then

If vc1 > 0 Then

' yx = "Or re Like & "" & row.Cells(1).Text & """

yx &= ListBox1.SelectedValue.ToString Like "" & row.Cells(1).Text & ""

Else

yx = "" & row.Cells(1).Text & ""

End If

vc1 = vc1 + 1

End If

Next

 

Answer 3

Firstly, if you want to compose the string with OR used in query, you need to do it like this:

yx=yx & " OR " & ListBox1.SelectedValue.ToString

Then, it's easier if you can debug the code line and line and watch the variables. Thanks.

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter