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

Edit & Delete commands not working in ITemplate.

3 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phaneendra
Top achievements
Rank 1
Phaneendra asked on 18 Sep 2012, 08:10 AM
HI,
I have a DataTable with Customer Data. I'm binding rad grid dynamically, because upton 3rd column, datatable has static columns after that from 4th columns all columns are Dynamic, so for that I've designed rad grid in dynamic binding and also binded column with Edit and Delete buttons. But the rad grid control item command event is not firing. Below is my code
void BindsGrid(int pageIndex = 0)
       {
 
           SetupTableService pgs = new SetupTableService();
           DataTable dt = pgs.ExportFuelGrade(SupplierId);
           int i = 0;
           if (gvFuelsGrades.MasterTableView.Columns.Count > 0)
           {
               gvFuelsGrades.MasterTableView.Columns.Clear();
               gvFuelsGrades.DataSource = null;
               gvFuelsGrades.DataBind();
                
           }
           foreach (DataColumn col in dt.Columns)
           {
               GridBoundColumn boundCol = new GridBoundColumn();
               string column = string.Format("{0}", dt.Columns[i].ColumnName);
               boundCol.DataField = column;
               boundCol.HeaderText = column;
               // templateCol.UniqueName = column.Replace(" ", string.Empty);
               gvFuelsGrades.MasterTableView.DataKeyNames = new string[] { "FuelId" };
               boundCol.ItemStyle.Width = Unit.Pixel(500);
               boundCol.ItemStyle.Wrap = true;
               if (boundCol.HeaderText == "FuelId" || boundCol.HeaderText == "OilGrade" || boundCol.HeaderText == "FuelGradeId" || boundCol.HeaderText == "ProductGroupId")
                   boundCol.Visible = false;
               gvFuelsGrades.MasterTableView.Columns.Add(boundCol);
                
               i++;
           }
            
           gvFuelsGrades.ClientIDMode = System.Web.UI.ClientIDMode.Static;
           gvFuelsGrades.CurrentPageIndex = pageIndex;
            
           gvFuelsGrades.AllowPaging = true;
           gvFuelsGrades.Width = Unit.Pixel(1000);
           gvFuelsGrades.DataSource = dt;
           gvFuelsGrades.DataBind();
            
            
           //(gvFuelsGrades.MasterTableView.GetColumn("Actions") as GridTemplateColumn).OrderIndex = gvFuelsGrades.Columns.Count+1;
           GridTemplateColumn templateCol = new GridTemplateColumn();
           templateCol.ItemTemplate = new GridActionTemplate("Actions");
           templateCol.HeaderText = "Actions";
           templateCol.OrderIndex = gvFuelsGrades.Columns.Count + 2;
           gvFuelsGrades.MasterTableView.Columns.Add(templateCol);
           gvFuelsGrades.Rebind();
           //(gvFuelsGrades.MasterTableView.GetColumn("Actions") as GridTemplateColumn).Visible = CanEdit() | CanDelete();
       }


and ITemplate Class
class GridActionTemplate : ITemplate
  {
      public event CommandEventHandler Command;
      private void OnCommand(CommandEventArgs e)
      {
          if (Command != null)
          {
              Command(this, e);
          }
 
      }
      private void imgEdit_Command(object sender, GridCommandEventArgs e)
      {
          OnCommand(e);
      }
      public void InstantiateIn(System.Web.UI.Control container)
      {
          lControl = new LiteralControl();
          lControl.ID = "lControl";
          imgEdit = new ImageButton();
          imgEdit.CommandName = "edit";
          imgEdit.ID = "btnEdit";
          imgEdit.ImageUrl = "~/Static/Images/Actions/edit.png";
           
 
          imgDelete = new ImageButton();
          imgDelete.CommandName = "delete";
          imgDelete.ImageUrl = "~/Static/Images/Actions/delete.gif";
           
          Table tbl = new Table();
          TableRow tr = new TableRow();
          TableCell td = new TableCell();
          td.Controls.Add(imgEdit);
          tr.Cells.Add(td);
          td = new TableCell();
          td.Controls.Add(imgDelete);
          tr.Cells.Add(td);
          tbl.Rows.Add(tr);
          container.Controls.Add(imgEdit);
          container.Controls.Add(imgDelete);
      }
      
      protected LiteralControl lControl;
      protected ImageButton imgEdit;
      protected ImageButton imgDelete;
      protected ImageButton imgView;
      private string colname;
      public GridActionTemplate(string cName)
      {
          colname = cName;
      }
  }

Help me in this regards  with making my rad grid fire item command.


Regards
Phaneendra

3 Answers, 1 is accepted

Sort by
0
Accepted
Radoslav
Telerik team
answered on 21 Sep 2012, 07:11 AM
Hello Phaneendra,

Could you please try commenting the following line and let me know if the issue still persists:
//gvFuelsGrades.ClientIDMode = System.Web.UI.ClientIDMode.Static;
Microsoft recommends using ClientIDMode=Static only for static control. RadControls on the other hand are controls with complex hierarchies of child controls and templates so setting their ClientID mode to static will break their functionality.
Also I am sending you a simple example, based on your code. Please check it out and let me know if it helps you.

Greetings,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Phaneendra
Top achievements
Rank 1
answered on 22 Sep 2012, 03:54 AM
Hi Radoslav
Thanks for your reply and its solved my problem and other thing i want to bring to your notice is how can we rotate the rad grid header text in 90 degrees and it need to be browser compatible.

Regards
Phaneendra
0
Radoslav
Telerik team
answered on 26 Sep 2012, 07:03 AM
Hello Phaneendra,

Currently, RadGrid does not support changing the orientation of header cells text. However
here are some options which may be helpful:
1. Use the writing-mode CSS property, but it works only in IE.
http://www.css3.com/css-writing-mode/
2. Set HeaderText by letters, not by words, so that the letters can wrap like this:

H
e
a
d
e
r
T
e
x
t

3. Use GridTemplateColumns with images in the HeaderTemplate. The images will contain the flipped vertical text.

Also you could check out the following links:
http://snook.ca/archives/html_and_css/css-text-rotation
http://stackoverflow.com/questions/278940/vertical-text-with-jquery
http://pupunzi.com/#mb.components/mb.flipText/flipText.html

I hope this helps.

Regards,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Phaneendra
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Phaneendra
Top achievements
Rank 1
Share this question
or