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

Grid / Accessing Cells and Rows

5 Answers 119 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
John
Top achievements
Rank 2
John asked on 16 Feb 2012, 09:48 PM

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

5 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 21 Feb 2012, 07:00 PM
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
0
John
Top achievements
Rank 2
answered on 24 Feb 2012, 03:40 PM
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
0
Plamen
Telerik team
answered on 28 Feb 2012, 11:42 AM
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
0
John
Top achievements
Rank 2
answered on 28 Feb 2012, 02:09 PM
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">
0
Plamen
Telerik team
answered on 01 Mar 2012, 02:37 PM
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
Tags
General Discussions
Asked by
John
Top achievements
Rank 2
Answers by
Plamen
Telerik team
John
Top achievements
Rank 2
Share this question
or