How to Access multiple selected rows on server

10 posts, 1 answers
  1. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 03 Apr 2013 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Apr 2013 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 03 Apr 2013 Link to this post

    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


  5. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 03 Apr 2013 Link to this post

    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
  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Apr 2013 Link to this post

    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
  7. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 05 Apr 2013 Link to this post

    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
  8. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 06 Apr 2013 Link to this post

    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
  9. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 08 Apr 2013 Link to this post

    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

  10. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 08 Apr 2013 Link to this post

    Hello,

    Please check below link.

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

    Thanks,
    Jayesh Goyani
  11. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 08 Apr 2013 Link to this post

    Thanks Jayesh

    I'll go with your suggestion

    Andy
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017