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

How to fetch values from EditIemTemplate of a dynamic GridTemplateColumn in batch edit mode

4 Answers 69 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Poulomi
Top achievements
Rank 1
Poulomi asked on 13 Oct 2015, 12:05 PM

I have a radgrid that I am dynamically creating in the Page_Init method as mentioned here. I have multiple templated columns that dispaly a label in the ItemTemplate and a RadComboBox and RadTimePicker in the EditItemTemplate. Both are properly displayed. However, on editing in batch mode, I am only able to get the value of the radcombobox and not of the time picker. I have noticed that the DataBinding events of my EditItemTemplate controls do not fire at all. Even the overridden ExtractValues method doesnt hit my breakpoint. Have attached the code..Any help is appreciated.

public class MyItemTemplate : IBindableTemplate
    {
        protected Label lblProj;
 
        private string colName;
 
 
        public MyItemTemplate(string cName)
        {
            colName = cName;
 
        }
 
        public void InstantiateIn(System.Web.UI.Control container)
        {
            lblProj = new Label();
            lblProj.ID = "ProjTime_" + colName;
            lblProj.Width = Unit.Pixel(140);
            lblProj.DataBinding += new EventHandler(lblProj_DataBinding);
            container.Controls.Add(lblProj);
        }
 
        void lblProj_DataBinding(object sender, EventArgs e)
        {
            Label lblProj = (Label)sender;
            GridDataItem container = (GridDataItem)lblProj.NamingContainer;
            lblProj.Text = ((DataRowView)container.DataItem)[colName].ToString();
        }
 
        public IOrderedDictionary ExtractValues(Control container)
        {
            OrderedDictionary values = new OrderedDictionary();
            return values;
        }
 
    }
public class MyEditTemplate : ITemplate
   {
       protected RadComboBox PDay;
       protected static string date;
       protected static string time;
       protected RadTimePicker PTime;
       private string colName;
       
       public MyEditTemplate(string cName)
       {
           colName = cName;
           
       }
 
       public IOrderedDictionary ExtractValues(Control container)
       { //breakpoint here doesnt get hit
           OrderedDictionary values = new OrderedDictionary();
                       return values;
       }
 
       
       public void InstantiateIn(System.Web.UI.Control container)
       {
           PDay = new RadComboBox();
           PDay.ID = "PDay_" + colName;
           PDay.Width = Unit.Pixel(150);
           PDay.AllowCustomText = true;
           PDay.DataBinding += new EventHandler(PDay_DataBinding);
 
           //adding Items to PDay.Items here
 
           PTime = new RadTimePicker();
           PTime .ID = "PTime_" + colName;
           PTime .Width = Unit.Pixel(100);
           PTime .DataBinding += new EventHandler(PTime_DataBinding);
           PTime .DateInput.ReadOnly = true;
 
           container.Controls.Add(PDay);
           container.Controls.Add(PTime );
 
       }
 
       void PTime_DataBinding(object sender, EventArgs e)
       { //breakpoint here doesnt get hit
           RadTimePicker timePicker = (RadTimePicker)sender;
           GridDataItem container = (GridDataItem)timePicker.NamingContainer;
           timePicker.SelectedDate = Convert.ToDateTime(((DataRowView)container.DataItem)[colName].ToString());
                   }
 
 
       public void PDay_DataBinding(object sender, EventArgs e)
       { //breakpoint here doesnt get hit
           RadComboBox cBox = (RadComboBox)sender;
           GridDataItem container = (GridDataItem)cBox.NamingContainer;
           cBox.Text = ((DataRowView)container.DataItem)[colName].ToString();
         }
 
 
 
   }

4 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 16 Oct 2015, 06:27 AM
Hello,

The reason why the ExtractValues method of the MyTemplate does not get hit is that this template inherits from ITemplate instead of IBindableTemplate. Please change the code accordingly and test whether this resolves the matter.

Additionally have in mind that the batch mode is designed in such a way that it will use the value of the first input on the client. That said could you please elaborate in detail on why exactly are two editors instantiated in the same template? How and from which editor should the value that will be inserted/updated in the database be extracted?

Regards,
Angel Petrov
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
Poulomi
Top achievements
Rank 1
answered on 21 Oct 2015, 08:56 AM

Hello Angel,

    

0
Poulomi
Top achievements
Rank 1
answered on 21 Oct 2015, 09:14 AM
Ugghh!  There should be a way to edit a response here.

Anyways, thanks Angel for the reply. I did notice the ITemplate later and changed it to IBindableTemplate and now the events get fired as they should.

On the other hand, as you mentioned, the batch edit mode does use only the first input control in the cell. I needed to have a combo box to select a day of the month and a RadTimePicker to select a particular time and then combine both of the values in codebehind. But I was unable to fetch the value of the timepicker. Each time I click on the SaveChanges, I only get the combo box value. But I needed both the controls, so I changed the edit mode to InPlace and fetched the values of the controls in ItemCommand event. It works fine this way but I would have really preferred the BatchEdit here as a user could update multiple rows and then save them in a go. Good for now though but would like to know if multi-editors could be supported in batch edit in future.
Thanks!  

0
Angel Petrov
Telerik team
answered on 26 Oct 2015, 06:36 AM
Hello,

You can use multiple editors to edit a single cell but this would require custom handling. The idea is to subscribe to the four batch events(OnBatchEditGetCellValue, OnBatchEditSetEditorValue, OnBatchEditGetEditorValue and OnBatchEditSetCellValue) as shown here and manually get/set the cell and editor values. The value which you pass to the arguments in the OnBatchGetEditorValue event will be the one that will be sent to the server later.

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