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

How do I capture ItemCommand arguments for RadGrid in VSTS Web Performance Tests?

1 Answer 488 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Cyber High
Top achievements
Rank 1
Cyber High asked on 08 Nov 2019, 09:44 PM

In my application, I have a Telerik RadGrid that contains student information. I'm using Visual Studio 2017 to load test some major changes to our system. To do that, I need to emulate a number of teachers performing various tasks in the system, each using the RadGrid to select a different student.

I've tried recording a Web Test, but I don't see anywhere to inject the selected student's ID value into the POST event that correlates with the ItemCommand event of the RadGrid that fires when a user clicks a student name on the grid.

I do see that the _EVENTTARGET parameter = 

ctl00$ContentPlaceHolder1$rgStudentList$ctl00$ctl04$btnLName

(which is the asp linkbutton in the last name field) but the _EVENTARGUMENTS parameter is empty.

I have searched the entire POST request and don't see anything like the commandarguments value I need.

Can anyone help me?


1 Answer, 1 is accepted

Sort by
0
Eric R | Senior Technical Support Engineer
Telerik team
answered on 13 Nov 2019, 05:40 PM

Hello,

Thank you for using the AJAX Forums. I wanted to mention that my colleague has replied to this question in the ticketing system and I am posting this response to assist anyone in the community with a similar issue.

In order to capture ItemCommand arguments, use a Button column or a Button inside a template column to make the Post Back. Each of these can define a CommandName that distinguishes the ItemCommand in the event handler. This then allows access to the Item, its data key value and process it further. See Accessing Cells and Rows article for more information on accessing items, values in a RadGrid.

Here is an example that you can try. Create a new WebForms page and add the following Grid markup to it:

<telerik:RadGrid ID="RadGrid1" runat="server" Width="800px" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand">
    <MasterTableView DataKeyNames="OrderID">
        <Columns>
            <telerik:GridButtonColumn CommandName="FirstCommand" ButtonType="PushButton" Text="First Button"></telerik:GridButtonColumn>
            <telerik:GridTemplateColumn>
                <ItemTemplate>
                    <telerik:RadButton ID="RadButton1" runat="server" Text="Second Button" CommandName="SecondCommand"></telerik:RadButton>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

And the following Code-behind:

protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    (sender as RadGrid).DataSource = Enumerable.Range(1, 3).Select(x => new
    {
        OrderID = x,
        OrderDate = DateTime.Now.Date.AddHours(x),
        Freight = x * .1,
        ShipName = "Name " + x,
        ShipCountry = "Country " + x
    });
}

protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    // The event arguments contains the Item (gridrow) where the command is coming from
    GridDataItem dataItem = e.Item as GridDataItem;

    // access the data key value (present in the DataKeyNames property of the MasterTable
    var OrderID = dataItem.GetDataKeyValue("OrderID");

    // Command name defined for the column or button
    if (e.CommandName == "FirstCommand")
    {
        // rune some logic
    }
    else if (e.CommandName == "SecondCommand")
    {
        // rune some other logic
    }
}

I hope this helps. Kindly refer to the support ticket response if this doesn't resolve the issue. Thank you.

Regards,


Eric R | Technical Support Engineer
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Ajax
Asked by
Cyber High
Top achievements
Rank 1
Answers by
Eric R | Senior Technical Support Engineer
Telerik team
Share this question
or