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

Update Data in Edit Mode RadGrid

6 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prathap
Top achievements
Rank 1
Prathap asked on 27 Oct 2008, 11:52 PM
Hi,
 I have data in a Data table.This datatable is stored in a session for frequent retrieval.
The data table acts as a data source for the radgrid. I am not able to get the updated value after edit.
Can I have an example how to update the data after edit in Rad Grid
Regards
Prathap.K.H

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Oct 2008, 03:16 AM
Hi Prathap,

Go through the following online demo which demonstrates how to perform Insert/Update Delete operations in RadGrid.
Automatic operations

Shinu.
0
Prathap
Top achievements
Rank 1
answered on 29 Oct 2008, 01:48 AM

Hi Shinu,
 Thanks for the quick response. I have problem in retrieving data after it has been updated.
The data retrieved is the old value.

<telerik:GridTemplateColumn Visible="true" HeaderText="Measure Volume" UniqueName="MeasureVolume">
    <HeaderStyle  Width="20px" />
       <ItemTemplate>
          <asp:Label ID="lblMeasureVolume" runat="server" Text='<%# Bind("MeasureVolume") %>'></asp:Label>
       </ItemTemplate>
       <EditItemTemplate>
       <telerik:RadNumericTextBox ID="txtVolume" Runat="server"
       BackColor="#FFFF99" CausesValidation="True" Culture="English (United States)"
       Height="13px" Skin="WebBlue" Width="70px" Text='<%# Bind("MeasureVolume") %>'>
       <NumberFormat AllowRounding="False" />
                                
       </telerik:RadNumericTextBox>
       <asp:RequiredFieldValidator ID="rqfldMeasurevolume" runat="server"
              ControlToValidate="txtVolume" ErrorMessage="Measure cannot be empty"></asp:RequiredFieldValidator>
                       
       </EditItemTemplate>
  </telerik:GridTemplateColumn> 
cs file

 

protected

void rdgrdTestCollection_ItemCommand(object source, GridCommandEventArgs e)

 

{

if (e.CommandName == "Update"){GridEditableItem editedItem = e.Item as GridEditableItem;
int rowNumber = editedItem.ItemIndex; // I'm checking which row is edited
//Update new values
string MeasureVolume = (editedItem.FindControl("MeasureVolume") as RadNumericTextBox).Text;

 

 

}

The data which I retrive is old value.How can I get the updated value.
At the same time is need to update this value in the data table.
Thanks in advance
Regards
Prathap.K.H
 

0
Princy
Top achievements
Rank 2
answered on 29 Oct 2008, 04:25 AM
Hello Prathap,

The code to access a control in the EditTemplate of a TemplateColumn is as:
Control cntrl =(Control)edititem["ColumnUniqueName"].FindControl("ControlID"); 

So in your case, you should be accessing the RadNumericTextBox as shown below.
string MeasureVolume = (editedItem["MeasureVolume"].FindControl("txtVolume") as RadNumericTextBox).Text; 

Thanks
Princy.
0
Prathap
Top achievements
Rank 1
answered on 29 Oct 2008, 03:59 PM
Hi,
 Thanks for the quick update.
Regards
Prathap.K.H
0
Prathap
Top achievements
Rank 1
answered on 29 Oct 2008, 07:23 PM
Hi,
 I am still not able to retrieve the updated value.
auotomatic properties like AllowAutomaticDeletes are set to flase exept sorting and paging.
I bind the radbrid on each post back with the session values.

 

void FillTestCollectionList()

 

{

 

bCollection.Columns.Add("MeasureVolume", typeof(System.Int32));

 

 

if (Session["testcollection"] != null)

 

tbCollection = (

DataTable)Session["testcollection"];

 

rdgrdTestCollection.AllowPaging =

true;

 

rdgrdTestCollection.AllowSorting =

true;

 

rdgrdTestCollection.DataSource = tbCollection;

rdgrdTestCollection.DataBind();

 }


<telerik:GridTemplateColumn Visible="true" HeaderText="Measure Volume" UniqueName="MeasureVolume">
    <HeaderStyle  Width="20px" />
       <ItemTemplate>
          <asp:Label ID="lblMeasureVolume" runat="server" Text='<%# Bind("MeasureVolume") %>'></asp:Label>
       </ItemTemplate>
       <EditItemTemplate>
       <telerik:RadNumericTextBox ID="txtVolume" Runat="server"
       BackColor="#FFFF99" CausesValidation="True" Culture="English (United States)"
       Height="13px" Skin="WebBlue" Width="70px" Text='<%# Bind("MeasureVolume") %>'>
       <NumberFormat AllowRounding="False" />
                                
       </telerik:RadNumericTextBox>
       <asp:RequiredFieldValidator ID="rqfldMeasurevolume" runat="server"
              ControlToValidate="txtVolume" ErrorMessage="Measure cannot be empty"></asp:RequiredFieldValidator>
                       
       </EditItemTemplate>
  </telerik:GridTemplateColumn> 

Is this the case why it is not retriving the updated value?
I am going crazy with it .Can anyone help me

protected

 

void rdgrdTestCollection_ItemCommand(object source, GridCommandEventArgs e)

 {

 

if (e.CommandName == "Update"){GridEditableItem editedItem = e.Item as GridEditableItem;
int rowNumber = editedItem.ItemIndex; // I'm checking which row is edited
//Update new values
string MeasureVolume = (editedItem.FindControl("MeasureVolume") as RadNumericTextBox).Text;

  }


0
Shinu
Top achievements
Rank 2
answered on 30 Oct 2008, 04:47 AM
Hi Prathap,

As Princy pointed you have to use the ControlID of the RadNumericTextBox(txtVolume is the controlID in your case) to access it on clicking the update button.

CS:
protected void rdgrdTestCollection_ItemCommand(object source, GridCommandEventArgs e)  
    {  
        if (e.CommandName == "Update")  
        {  
            GridEditableItem eeeditedItem = e.Item as GridEditableItem;  
            int rowNumber = editedItem.ItemIndex;  
            // I'm checking which row is edited  
            //Update new values  
            RadNumericTextBox numTxtbx = (RadNumericTextBox)editedItem["MeasureVolume"].FindControl("txtVolume");  
            string MeasureVolume = numTxtbx.Text;   
        }  
         
    }  


Also try binding the Grid using AdvanceDataBinding techniques.

Regards
Shinu.
Tags
Grid
Asked by
Prathap
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Prathap
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or