
Being new to this tool, I hava requirement where by I have a Rad Grid and when I submit / click Add new Record button the text boxes to be filled automatically after some calculated values from the previous rows.
Please help in this this issues as ItemCommand is not allowing me to have access to the text boxes.
Regards
SS Bhogal
4 Answers, 1 is accepted

I am not quite sure about your requirement.Please take a look into the following sample code snippet to access the textox in ItemCommand Event while adding new record.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"false"
onitemcommand
=
"RadGrid1_ItemCommand"
onneeddatasource
=
"RadGrid1_NeedDataSource"
>
<
MasterTableView
CommandItemDisplay
=
"Top"
>
<
Columns
>
<
telerik:GridBoundColumn
UniqueName
=
"OrderID"
HeaderText
=
"OrderID"
DataField
=
"OrderID"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"CustomerID"
HeaderText
=
"CustomerID"
DataField
=
"CustomerID"
></
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
C#:
protected
void
RadGrid1_ItemCommand(
object
sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.InitInsertCommandName)
{
e.Canceled =
true
;
e.Item.OwnerTableView.InsertItem();
GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
GridEditFormItem editFormItem = insertedItem
as
GridEditFormItem;
TextBox OrderID = (TextBox)editFormItem[
"OrderID"
].Controls[0];
OrderID.Text =
"your text"
;
}
}
Thanks,
Shinu.

But it did not work. The thing is I am doing is -
<telerik:GridTemplateColumn HeaderText="Amount From" AllowFiltering="false"
HeaderStyle-Width="15%">
<ItemTemplate>
<asp:Label ID="lbl_TxnAmtFrom" runat="server" Text='<%#Eval("TransactionAmountFrom")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<span>
<asp:TextBox runat="server" ID="txt_TxnAmtFrom" Width="150px" Text='<%# Bind("TransactionAmountFrom") %>'>
</asp:TextBox><span style="color: Red">
</span>
</EditItemTemplate>
<HeaderStyle Width="15%"></HeaderStyle>
</telerik:GridTemplateColumn>
I attached the picture I need.

Access the Label 'AmountTo' in ItemDataBount event and store the value of the Label in a global variable and do the calculation, then access the TextBox 'AmountFrom' in the ItemCommand event while adding new record and assign the global variable value in the TextBox. Please take a look into the following code snippet.
C#:
public
static
int
value = 0;
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem ditem = (GridDataItem)e.Item;
Label OrderID = (Label)ditem.FindControl(
"lbl_TxnAmtTo"
);
value=Convert.ToInt32(OrderID.Text);
value = value + 1;
}
}
protected
void
RadGrid1_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.InitInsertCommandName)
{
e.Canceled =
true
;
e.Item.OwnerTableView.InsertItem();
GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
GridEditFormItem editFormItem = insertedItem
as
GridEditFormItem;
TextBox OrderID = (TextBox)editFormItem.FindControl(
"txt_TxnAmtFrom"
);
OrderID.Text = value.ToString();
}
}
Thanks,
Shinu.

Thanks Shinu,
I could do it yesterday by getting the control in the RadGrid as -
e.Canceled = true;
e.Item.OwnerTableView.InsertItem();
GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
TextBox box = insertedItem.FindControl("txt_TxnAmtFrom") as TextBox;
It could solve my purpose and of-course thank you for the efforts you did.
Regards
SS Bhogal