<telerik:GridTemplateColumn HeaderText="Amount" UniqueName="Amount" SortExpression="Amount" Aggregate="Custom" DataField="Amount">
<ItemTemplate><asp:TextBox runat="server" ID="txtAmount" Text='<%# Eval("Amount") %>'
DataFormatString="{0:C}" ></asp:TextBox>
</ItemTemplate></telerik:GridTemplateColumn>
In the above code, initially, I used only ItemTemplate and added Textbox in it and tried to get the value entered by user in the ItemCommand event. But I couldn't get the new value from Textbox. It is giving the old value
I had used below code in the Itemcommand event to get the new value, but, didn't get the new value.
protected void grdPaymentHistory_OnItemCommand(object sender, GridCommandEventArgs e)
{
var dataItem = e.Item as GridDataItem;var refundAmount = (TextBox)dataItem["Amount"].Controls[1];
}
Later on, I thought that edited values may not be available in ItemTemplate. So, I used editItemTemplate which is containing textbox and validator.Now, when user clicks on edit button (GridEditcommandcolumn), textbox is avialable for entering the amount. I am trying to get the value entered by user in the textbox in the edititemtemplate. I am trying to get the value in ItemCommand event. Below is the Itemcommand event.
Here, I am getting the old value i.e the value which was there initially before the user edited.
<ItemTemplate>
<asp:Label runat="server" ID="lblAmount" Text='<%# Eval("Amount") %>'DataFormatString="{0:C}"></asp:Label></ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtAmount" Text='<%# Eval("Amount") %>'DataFormatString="{0:C}" ></asp:TextBox>
<asp:CustomValidator ID="RefundamountValidator" runat="server" ControlToValidate="txtAmount"
OnServerValidate="RefundAmountValidation" ValidateEmptyText="True"
ErrorMessage="Reassign To cannot be the same as Assigned To" SetFocusOnError="true"Text="*" Display="Dynamic" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
protected void grdPaymentHistory_OnItemCommand(object sender, GridCommandEventArgs e)
{
foreach (GridDataItem item in grdPaymentHistory.EditItems){
var TextBox1 = item.FindControl("txtAmount") as TextBox; }
}
Please provide your valuable inputs to get the new value in both ItemTemplate and EditItemTemplate.
Thanks