Grid / Accessing Cells and Rows

6 posts, 0 answers
  1. John
    John avatar
    8 posts
    Member since:
    Jul 2012

    Posted 16 Feb 2012 Link to this post

    I need to access a grid by the ROW and Column.  My thought is to search for some data in this example would be search for Order ID, Ship name, or Ship address to click that rows edit button.  Can you provide some sample code in VB?

    Thanks,

    John

    http://demos.telerik.com/aspnet-ajax/grid/examples/programming/accessingcellsandrows/defaultcs.aspx

  2. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 21 Feb 2012 Link to this post

    Hello John,

    The following code will search in all cells from the second column of the Grid, for a text content "10250" and if such cell exists will click on the Edit button at the end of the row. 
    Dim table As GridTableView = Pages.ASPNETGridDemoRows.RadGrid1Div.MasterTable
     
    For Each r As GridDataItem In table.DataItems
        
        If r.DataCells(1).CellText = "10250" Then
            r.DataCells(5).EditButtonClick()
        End If
    Next

    Hope this helps!

    Regards,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. John
    John avatar
    8 posts
    Member since:
    Jul 2012

    Posted 24 Feb 2012 Link to this post

    Thats great but in my case I have more than one button in the same cell.  How can I click a button if there are more than one?
    thanks,
    John
  4. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 28 Feb 2012 Link to this post

    Hi,

    If you have more than one button in the same cell, you can use the Find method to find the one you want to click on. For example, you can search for the correct button using its "Id". Here's the code:
    Dim table As GridTableView = Pages.ASPNETGridDemoRows.RadGrid1Div.MasterTable
     
    For Each r As GridDataItem In table.DataItems
        If r.DataCells(1).CellText = "10250" Then
            Dim button As RadButton = r.DataCells(5).Find.ById(Of RadButton)("RadGrid1_ctl00_ctl08_EditButton")
            Assert.IsNotNull(button)
            button.Click()
        End If
    Next

    Let me know if you need further assistance on this. 

    All the best,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  5. John
    John avatar
    8 posts
    Member since:
    Jul 2012

    Posted 28 Feb 2012 Link to this post

    that's great however, if I follow the logic, the same button ID would be clicked and the are different for row.  Both title and src seems to be the same in that case. Is there a way to search of off them?

    Thanks,
    John

    <input id="RadGrid1_ctl00_ctl18_EditButton" type="image" style="border-width:0px;" alt="Edit" src="/aspnet-ajax/WebResource.axd?d=d-BcrlfuZmsnmnYalHdQF0f_mIsyCw821MSYRUCnS4HZccSfqjA93arjnQvEKAUkY9qPVV1egYEl4iBV6m1iW15DuTQZJ4n0cl3O6ueycSYwI7tPIB243P32nHXE8FyCRirmjP_rUn0V6mIZSIrjXJinyw3doJ3dDWYdiqNhDlFYm-tNOQwFaECvqb1jYby50&t=634648802539945625" title="Edit" name="RadGrid1$ctl00$ctl18$EditButton">
     
    <input id="RadGrid1_ctl00_ctl04_EditButton" type="image" style="border-width:0px;" alt="Edit" src="/aspnet-ajax/WebResource.axd?d=d-BcrlfuZmsnmnYalHdQF0f_mIsyCw821MSYRUCnS4HZccSfqjA93arjnQvEKAUkY9qPVV1egYEl4iBV6m1iW15DuTQZJ4n0cl3O6ueycSYwI7tPIB243P32nHXE8FyCRirmjP_rUn0V6mIZSIrjXJinyw3doJ3dDWYdiqNhDlFYm-tNOQwFaECvqb1jYby50&t=634648802539945625" title="Edit" name="RadGrid1$ctl00$ctl04$EditButton">
  6. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 01 Mar 2012 Link to this post

    Hi John,

    The first part of the ID is different, but both IDs ends with "EditButton", so you can use the following code:
    'Click on the first edit button in the cell
    Dim firstButton As RadButton = r.DataCells(5).Find.ByCustom(Of RadButton)(Function(button) button.ID.EndsWith("EditButton"))
    firstButton.Click()


    If you have more than one Edit button in a single cell, you can use the following code to click on the second button:
    'Click on the second edit button in the same cell
    Dim firstButton As RadButton = r.DataCells(5).Find.AllByCustom(Of RadButton)(Function(button) button.ID.EndsWith("EditButton"))(1)
    firstButton.Click()

    Hope this helps!

    All the best,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top
  Cast Your Vote at DevPro Connections! Cast Your Vote at  Win IT Pro Connections!