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

Merging Edit and Delete Columns in Radgrid

2 Answers 166 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Smart
Top achievements
Rank 1
Smart asked on 24 Oct 2013, 03:44 PM
Hello All, 
          Is there a way to merge these two columns? This is what I have right now   (please look at the current file). This is how I created these two columns from code-behind
GridEditCommandColumn EditColumn = new GridEditCommandColumn();
 this.RadGrid1.MasterTableView.Columns.Add(EditColumn);
 EditColumn.ButtonType = GridButtonColumnType.ImageButton;
 EditColumn.UniqueName = "EditCommandColumn";
 EditColumn.HeaderText = "SingleAction";
 EditColumn.ColumnGroupName = "test";
                          
 GridButtonColumn DeleteColumn = new GridButtonColumn();
 this.RadGrid1.MasterTableView.Columns.Add(DeleteColumn);
 DeleteColumn.CommandName = "Delete";
 DeleteColumn.ButtonType = GridButtonColumnType.ImageButton;
 DeleteColumn.UniqueName = "DeleteCommandColumn";
 DeleteColumn.ConfirmDialogType = GridConfirmDialogType.Classic;
 DeleteColumn.HeaderText = "SingleAction";
 DeleteColumn.ConfirmText = "Do you really want to delete?";
 I want to achieve something like this (please look at desired file). I have tried to do the GridCalculatedColumn. And the code for that is
GridCalculatedColumn calcol = new GridCalculatedColumn();   
 calcol.DataFields =new string[]{"EditCommandColumn","DeleteCommandColumn"};   
 calcol.Expression ="{0}-{1}";  
 tableViewProjects.Columns.Add(calcol);                          
I get an error column [EditCommandColumn] does not exist, which I think makes sense, because it not a data field from the database.
 So, is there a way to achieve this. Please help

Thank you in advance 

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 25 Oct 2013, 06:45 AM
Hi Satish,

I have tried to implement your required scenario using MultiColumnHeaders.Please try the following code snippet.

ASPX:
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

C#:
protected void Page_Init(object sender, EventArgs e)
   {
       RadGrid grid = new RadGrid();
       grid.AutoGenerateColumns = false;
       grid.DataSourceID = "SqlDataSource1";       
       
       GridBoundColumn boundColumn1 = new GridBoundColumn();
       boundColumn1.DataField = "ContactName";
       boundColumn1.UniqueName = "ConactName";
       boundColumn1.HeaderText = "ConactName";
       
       grid.MasterTableView.Columns.Add(boundColumn1);
       grid.AllowPaging = true;      
       grid.Skin = "Outlook";      
 
       GridColumnGroup columnGroup = new GridColumnGroup();
       columnGroup.HeaderText = "Single Action";
       columnGroup.Name ="SingleAction";
       grid.MasterTableView.ColumnGroups.Add(columnGroup);
       
           GridEditCommandColumn EditColumn = new GridEditCommandColumn();
           grid.MasterTableView.Columns.Add(EditColumn);       
           EditColumn.ButtonType = GridButtonColumnType.ImageButton;
           EditColumn.UniqueName = "EditCommandColumn";         
           EditColumn.ColumnGroupName = "SingleAction";
           EditColumn.HeaderStyle.CssClass = "header";
 
           GridButtonColumn DeleteColumn = new GridButtonColumn();
           grid.MasterTableView.Columns.Add(DeleteColumn);
           DeleteColumn.CommandName = "Delete";
           DeleteColumn.ButtonType = GridButtonColumnType.ImageButton;
           DeleteColumn.UniqueName = "DeleteCommandColumn";
           DeleteColumn.ConfirmDialogType = GridConfirmDialogType.Classic;         
           DeleteColumn.ConfirmText = "Do you really want to delete?";
           DeleteColumn.ColumnGroupName = "SingleAction";
           DeleteColumn.HeaderStyle.CssClass = "header";
 
       PlaceHolder1.Controls.Add(grid);
   }

CSS:
<style type="text/css">
 .header
 {
  display: none;
 }
</style>

Thanks,
Princy
0
Smart
Top achievements
Rank 1
answered on 25 Oct 2013, 01:01 PM
Thank you Princy, that worked like a charm. 
Tags
Grid
Asked by
Smart
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Smart
Top achievements
Rank 1
Share this question
or