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

Getting to the ImageButton in RadGrid - MouseClick to initiate command

2 Answers 93 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Athadu
Top achievements
Rank 1
Athadu asked on 10 Dec 2010, 04:23 AM

Hi,

I have the following RadGrid as shown in the code snippet.  Inside a Unit Test code using ArtOfTest.WebAii.TestTemplates etc. library in C#, I am trying to get to the EditColumn ImageButton and mimic a click on the image to initiate a 'edit item' operation.
I have the grid using (RadGrid grid = Find.ById<RadGrid>("RadGrid1");).

How do I get to the HtmlImageButton or equivalent object for a specific row in the MasterTable?
I would greatly appreciate any pointers.

<telerik:RadGrid ID="RadGrid1" runat="server"  AllowSorting="True"
    PageSize="5" AllowPaging="True" OnItemCreated="RadGrid1_ItemCreated" OnColumnCreated="RadGrid1_ColumnCreated"
    OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand"
    OnItemDataBound="RadGrid1_ItemDataBound" OnUpdateCommand="RadGrid1_UpdateCommand"
    OnDeleteCommand="RadGrid1_DeleteCommand"
    <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle
    <MasterTableView DataKeyNames="ID" CommandItemDisplay="Top" AutoGenerateColumns="false"
        ShowHeadersWhenNoRecords="true" 
    
        <CommandItemTemplate
            <div style="padding: 5px 5px;"
                  <asp:LinkButton ID="btnRebind" runat="server" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" 
                alt="" src="Images/Refresh.gif" />Refresh</asp:LinkButton
            </div
        </CommandItemTemplate
        <Columns
            <telerik:GridButtonColumn UniqueName="InsertColumn" ButtonType="ImageButton" CommandName="AddItem"  ImageUrl="~/Images/AddRecord.gif" HeaderStyle-Width="20px"  HeaderText="Create New Item"/> 
            <telerik:GridButtonColumn UniqueName="EditColumn" ButtonType="ImageButton"  CommandName="EditItem" HeaderStyle-Width="20px"  HeaderText="Edit/View Item" /> 
            <telerik:GridBoundColumn DataField="ID" Visible="false" /> 
        </Columns
    </MasterTableView
    <ClientSettings
        <Selecting AllowRowSelect="true" /> 
    </ClientSettings
</telerik:RadGrid>


Regards
Athadu

2 Answers, 1 is accepted

Sort by
0
Pavel
Telerik team
answered on 14 Dec 2010, 05:01 PM
Hi Athadu,

The simplest approach is to find the button by its id and click it:
HtmlInputControl firstRowEditButton = Find.ById<HtmlInputControl>("RadGrid1_ctl00_ctl04_EditButton");
firstRowEditButton.MouseClick();

The above code works for this page. Alternatively you can find the data item you want to edit in the Grid and within it look for a control with part of the id of your image button.

All the best,
Pavel
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Athadu
Top achievements
Rank 1
answered on 08 Jan 2011, 05:50 AM
Thank you.  That worked for me.

Regards
Athadu
Tags
General Discussions
Asked by
Athadu
Top achievements
Rank 1
Answers by
Pavel
Telerik team
Athadu
Top achievements
Rank 1
Share this question
or