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

RadGrid with multiple edit Buttons

4 Answers 331 Views
Grid
This is a migrated thread and some comments may be shown as answers.
diego
Top achievements
Rank 1
diego asked on 30 May 2017, 10:48 AM

hello

i have the following problem. i have a radgrid which is totally created at runtime and i need to add two ways of editing

i mean,  i added a GridEditCommandColumn and then, because only one GridEditCommandColumn can be added to radgrid, i created a GridButtonColumn

here is the code:

GridEditCommandColumn eCol = new GridEditCommandColumn();
eCol.HeaderStyle.Width = Unit.Pixel(30);
eCol.UniqueName = "EditCommandColumn";
eCol.ItemStyle.CssClass = "edit_btn";
eCol.UpdateText = "Save changes";
grid.MasterTableView.Columns.Add(eCol);
 
GridButtonColumn cCol = new GridButtonColumn();
cCol.ButtonType = GridButtonColumnType.LinkButton;
cCol.UniqueName = "CorrectColumn";
cCol.ItemStyle.CssClass = "edit_btn";
cCol.CommandName = "Edit";
cCol.Text = "Correct";
grid.MasterTableView.Columns.Add(cCol);

the problem rises when in the radGrid_ItemCommand event i need to execute two different operations due to which button has been clicked

here is the pseudocode:

if (e.CommandName == "Edit")
{
    //get button name or id
}
if (e.CommandName == "Update")
{
    if (button_name=='Edit') do exec 1
    else if (button_name=='Correct') do exec 2
}

how can i solve ?

thanks in advance

4 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 01 Jun 2017, 08:03 AM
Hello Diego,

You can create 2 GridButtonColumns, one with CommandName="MyEditCommand" and the second one with CommandName="MyCorrectCommand" and use the e.CommandName argument in the ItemCommand event handler to execute the appropriate logic depending on the clicked button.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
diego
Top achievements
Rank 1
answered on 01 Jun 2017, 01:39 PM

Hello Eyup,

thanks for your reply. I have done as you suggested but the problem is related to the Update command

I mean, both MyEditCommand and MyCorrectCommand must put the grid in Edit Mode. In this way there is a unique Upload (and Cancel) button that, once clicked, performs the Upload command. 

I am thinking to solve in this way: declare a static variable  (say editMode)

if (e.CommandName == "Edit")
{
    editMode=1;
}
if (e.CommandName == "Correct")
{
    editMode=2;
}

and then 

if (e.CommandName == "Update")
{
if(editMode==1) do something;
else if(editMode==2)  do something-else;
}

 

 

do you think is it right?

thank you

 

 

0
Eyup
Telerik team
answered on 06 Jun 2017, 01:05 PM
Hi Diego, 

If you are using the default EditForms edit mode you can use the mentioned approach. Alternatively, you can also use a edit form template and change the button text and command accordingly:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/form-template-update/defaultcs.aspx

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
diego
Top achievements
Rank 1
answered on 06 Jun 2017, 01:25 PM

Hi Eyup

The approach I am following is working

thank you!

Tags
Grid
Asked by
diego
Top achievements
Rank 1
Answers by
Eyup
Telerik team
diego
Top achievements
Rank 1
Share this question
or