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

Adding a ClientEvent command breaks button columns

1 Answer 34 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 21 May 2015, 04:06 PM

Hi,

 If you have a radgrid with a button column that fires a command when pressed like so:

 <telerik:GridButtonColumn UniqueName="btnCol" HeaderText="Script" CommandName="BtnPressed" Text="Show">
</telerik:GridButtonColumn>

 

Then in the c# event function for the radgrid:

 

protected void RadGrid_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "BtnPressed")
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                string cellVal = Convert.ToString(item["cellOne"].Text);

 

Everything works fine, if you click on row 0, cellVal will equal the value of [row 1, cell 1], if you click row 3, cellVal will equal the value of [row 3, cell 1], etc.

Adding this to the radgrid:

 <ClientSettings>
            <ClientEvents OnCommand="OnCommand" />
 </ClientSettings>

 

And then this javascript:

 

function OnCommand(sender, args) {

// Empty function
 }

 

This will completely break the rad grid button column. Now if you click a button on any row in the grid, you will always receive data from the first row in the RadGrid_ItemCommand function. E.g if you click on the button in row 6 you will receive the data from [row 1, cell 1].

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 26 May 2015, 08:16 AM
Hello Matt,

When you attach handler for the client-side OnCommand event of the grid, the GridButtonColumn will 
work in a slightly different way, because it will fire the command through the MasterTableView and its fireCommand method with the button's custom command name and the row index as an argument. With that approach, the item from the server-side OnCommand arguments will be the first data item in the grid, so you will have to use the event's command argument for retrieving the data item index:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "BtnPressed")
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)RadGrid1.Items[int.Parse(e.CommandArgument.ToString())];
            string cellVal = Convert.ToString(item["cellOne"].Text);
        }
    }
}

Hope this helps.


Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or