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

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

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

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.

Thanks for the quick update.
Regards
Prathap.K.H

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>
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;
}

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.