This is a migrated thread and some comments may be shown as answers.

How to Access multiple selected rows on server

9 Answers 93 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy Green
Top achievements
Rank 2
Andy Green asked on 03 Apr 2013, 06:12 AM
Hi All

I have a gridTemplateColumn with a Checkbox, I'm having problems accessing the selected rows (multiple)

How would I do this in my senareo without a GridClientSelectColumn

Andy

9 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Apr 2013, 06:51 AM
Hi,

Try the following code to achieve your scenario.
C#:
protected void Button1_Click(object sender, EventArgs e)
{
    foreach (GridDataItem item in RadGrid1.SelectedItems)
    {
            CheckBox chk = (CheckBox)item.FindControl("CheckBox1");
    }
}

Thanks,
Shinu
0
Andy Green
Top achievements
Rank 2
answered on 03 Apr 2013, 07:05 AM
Thanks Shinu for the quick response.

I have a text box in each row, how would I address to get the data for each selected row.

Andy

PS I think I have it.

 

Dim txt As TextBox = DirectCast(item.FindControl("txtValue"), TextBox)

 

Dim value As String = txt.Text


0
Andy Green
Top achievements
Rank 2
answered on 03 Apr 2013, 07:33 AM
Hi

The SelectedItems collection is always Empty, How does the grid know I have made a selection, by ticking the check boxes. The check box is in a template, its not the clientSelectColumn

Andy
0
Shinu
Top achievements
Rank 2
answered on 05 Apr 2013, 05:26 AM
Hi,

Try the following code.
C#:
Protected Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs)
    Dim chk As CheckBox = DirectCast(sender, CheckBox)
    Dim item As GridDataItem = DirectCast(chk.NamingContainer, GridDataItem)
    Dim txt As TextBox = DirectCast(item.FindControl("TextBox1"), TextBox)
End Sub

Thanks,
Shinu
0
Andy Green
Top achievements
Rank 2
answered on 05 Apr 2013, 08:14 PM
Thanks again, but still not what I'm after.

I cant do this on the individual clicks, I want the user to select a few check boxes, and when they hit submit, it then in the button click event that I need to get a list of all selected rows.

Andy
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 06 Apr 2013, 11:31 AM
Hello,

Protected Sub Button1_Click(sender As Object, e As EventArgs)
    For Each item As GridDataItem In RadGrid1.MasterTableView.Items
        Dim chk As CheckBox = DirectCast(item.FindControl("CheckBox1"), CheckBox)
        If chk.Checked Then
                ' Access your TextBox Here
            Dim txtValue As TextBox = DirectCast(item.FindControl("txtValue"), TextBox)
        End If
    Next
End Sub


Thanks,
Jayesh Goyani
0
Andy Green
Top achievements
Rank 2
answered on 08 Apr 2013, 07:36 AM
Thanks Jayesh

I have used the following syntax:

For Each item As GridDataItem In rgProcedures.Items...

What would be the difference in using  .Masterview

Andy

0
Jayesh Goyani
Top achievements
Rank 2
answered on 08 Apr 2013, 12:19 PM
Hello,

Please check below link.

http://www.telerik.com/help/aspnet-ajax/grid-mastertableview-difference.html

Thanks,
Jayesh Goyani
0
Andy Green
Top achievements
Rank 2
answered on 08 Apr 2013, 12:40 PM
Thanks Jayesh

I'll go with your suggestion

Andy
Tags
Grid
Asked by
Andy Green
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Andy Green
Top achievements
Rank 2
Jayesh Goyani
Top achievements
Rank 2
Share this question
or