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

GridButtonColumn problem with Delete Command

3 Answers 223 Views
Grid
This is a migrated thread and some comments may be shown as answers.
diego
Top achievements
Rank 1
diego asked on 29 Oct 2015, 01:51 PM

Hello

I have a little problem with a GridButtonColumn in a RadGrid. First of all, the grid is completeley created by code. I need to manage editing, insert and delete operations. Everythimg works good, except that I would like to have a confirm message before the delete command occurs.

Here follows the code:

RadGrid grid = new RadGrid();
grid.ID = "instGrid";
grid.DataSourceID = "sqlInst";
grid.PageSize = 15;
grid.AllowPaging = true;
grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
grid.AutoGenerateColumns = false;
grid.AllowAutomaticUpdates = false;
grid.AllowAutomaticInserts = false;
grid.AllowAutomaticDeletes = false;
grid.ItemCommand += new GridCommandEventHandler(instGrid_ItemCommand);
 
//2.1 Add Customers table 
grid.MasterTableView.DataKeyNames = new string[] { "id_badmstorage", "value" };
grid.MasterTableView.EditMode = GridEditMode.EditForms;
grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
GridBoundColumn boundColumn = new GridBoundColumn();
boundColumn.DataField = "id_badmstorage";
boundColumn.HeaderText = "ID";
boundColumn.ReadOnly = true;
grid.MasterTableView.Columns.Add(boundColumn);
 
//2.2 SET SQL DATA SOURCE...
 
sqlInst.SelectCommand = "SELECT * FROM DataTable WHERE variableID=" + bv.ID + " AND siteID=438 AND dataStatus=0";
//3. Add grid columns...
GridTemplateColumn tempC = null;//new GridTemplateColumn();
tempC = new GridTemplateColumn();
tempC.DataField = "value";
tempC.HeaderText = bv.Name;
tempC.ItemTemplate = new MyTemplate("value", bv.CvIndex, true);
tempC.EditItemTemplate = new CustomEditTemplate("value", true, bv.Unit, bv.CvIndex);
grid.MasterTableView.Columns.Add(tempC);
 
//4. Edit commands
GridEditCommandColumn eCol = new GridEditCommandColumn();
grid.MasterTableView.Columns.Add(eCol);
eCol.UniqueName = "EditCommandColumn";
 
//5. delete command
GridButtonColumn delCol = new GridButtonColumn();
grid.MasterTableView.Columns.Add(delCol);
delCol.HeaderText = "Delete";
delCol.UniqueName = "Delete";
delCol.CommandName = "Delete";
delCol.ConfirmDialogType = GridConfirmDialogType.Classic;
delCol.ConfirmTitle = "Delete";
delCol.ButtonType = GridButtonColumnType.ImageButton;
 
// Add the grid to the placeholder 
this.PlaceHolder1.Controls.Add(grid);
 
//AJAX SETTINGS...
AjaxSetting ajax = new AjaxSetting(grid.ID);
AjaxUpdatedControl up=new AjaxUpdatedControl();
up.ControlID=grid.ID;
ajax.UpdatedControls.Add(up);
up = new AjaxUpdatedControl();
ajax.UpdatedControls.Add(up);
RadAjaxManager1.AjaxSettings.Add(ajax);

The grid is created in the Page_Init event

A preview of the page can be found at this link (select INST_MODEL from the list)

If you try to delete a record, no confirm window appears (deletion is disabled for now)

Thanks

Diego

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 03 Nov 2015, 07:49 AM
Hello Diego,

When creating the grid during Page_Init, you should first the set the properties of the column and then add it to the Columns collection of the corresponding GridTableView: grid.MasterTableView.Columns.Add(delCol);:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/creating-a-radgrid-programmatically#Section22

Hope this helps. Please make the suggested modification and let me know about the result.

Regards,
Eyup
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
0
diego
Top achievements
Rank 1
answered on 03 Nov 2015, 12:27 PM

Hello Eyup

Thanx for your suggestions, I have changed the code in this way:

 

//5. delete command
GridButtonColumn delCol = new GridButtonColumn();
 
delCol.UniqueName = "Delete";
delCol.CommandName = "Delete";
delCol.ConfirmDialogType = GridConfirmDialogType.Classic;
delCol.ConfirmTitle = "Delete Item";
delCol.Text = "Delete";
delCol.ButtonType = GridButtonColumnType.LinkButton;
grid.MasterTableView.Columns.Add(delCol);

but it still doesn't work...

0
Eyup
Telerik team
answered on 24 Nov 2015, 09:57 AM
Hi Diego,

It is possible that this problem is due to a script issue. Could you temporarily disable any AJAX on the page if present (RadAjaxManager, RadAjaxPanel, UpdatePanel, etc.) and enable your script debugger (FireBug or F12) to see whether there are any script or server errors interfering?

Regards,
Eyup
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
diego
Top achievements
Rank 1
Answers by
Eyup
Telerik team
diego
Top achievements
Rank 1
Share this question
or