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

How to update data using RadGrid1_ItemComand

0 Answers 32 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Duan
Top achievements
Rank 1
Duan asked on 10 Jul 2012, 04:39 PM
Hi everybody,

I'm new on Telerik.

I wrote this code below, for CRUD operations:

The insert command worked perfectly, but Update did not.

On first attemp (TextBox)e.Item.FindControl("txtComponente");  return null, and I do not understand why 
On second attemp item.UpdateValues(obj);  do nothing

Anybody can help me?

Thanks in advance.

 
public void RadGrid1_ItemComand(Object sender , GridCommandEventArgs e)
       {
           switch (e.CommandName)
           {
               case "Insert" :
                   try
                   {
                       TextBox txtComponente = (TextBox)e.Item.FindControl("txtComponente");
                       TextBox txtDescricaoComponente = (TextBox)e.Item.FindControl("txtDescricaoComponente");
                       Inserir(txtComponente.Text, txtDescricaoComponente.Text);
 
                       DisplayMessage(false, "Sucess!");
                       Response.Redirect("ConsultaComponente.aspx");
                   }
                   catch ( Exception ex)
                   {
                       DisplayMessage(true, ex.Message);
                   }
                   break;
 
               case "Update" :
                   try
                   {
 
                       //First attempt
                       var ID = item.GetDataKeyValue("IdComponente").ToString();
                        
                       TextBox txtComponente = (TextBox)e.Item.FindControl("txtComponente");
                       TextBox txtDescricaoComponente = (TextBox)e.Item.FindControl("txtDescricaoComponente");
                       Update(ID,txtComponente.Text, txtDescricaoComponente.Text);
                        
                        
                       //Second attempt
 
                       GridEditableItem item = e.Item as GridEditableItem;
                        
                       var ID = item.GetDataKeyValue("IdComponente").ToString();
 
                       Componente obj = ComponenteController.Consulta(Convert.ToInt32(ID));
                       
                       item.UpdateValues(obj);
 
                       Update(obj)
                   }
                   catch (Exception ex)
                   {
                       DisplayMessage(true, ex.Message);
                   }
                   break;
           }

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Duan
Top achievements
Rank 1
Share this question
or