0

My Telerik:RadGrid tag :

<telerik:RadGrid ID="grdSettlement" runat="server" AllowFilteringByColumn="True"
    DataSourceID="SqlDataSource1" AllowAutomaticDeletes="True" AllowAutomaticUpdates="True"
    AllowAutomaticInserts="true" OnInsertCommand="grdSettlement_InsertCommand">

My Columns :

<telerik:GridTemplateColumn DataField="NO" FilterControlAltText="Filter NO column"
                HeaderText="NO" SortExpression="NO" UniqueName="NO" DataType="System.Int64">
                <InsertItemTemplate>
                    <telerik:RadNumericTextBox runat="server" ID="No">
                    </telerik:RadNumericTextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <%# Eval("NO") %>
                </ItemTemplate>
            </telerik:GridTemplateColumn>

C# code to access that :

protected void grdSettlement_InsertCommand(object source, GridItemEventArgs e)
{
    ((e.Item as GridEditableItem)["NO"].Controls[0] as TextBox).Text = "007";
}

I can Write that some codes but there are give me a Compilation Error... Help me to Solve this...

Ankur
  • 519
  • 8
  • 15

3 Answers3

2

It's Working with this :

.aspx

<telerik:RadGrid ID="grdSettlement" runat="server" AllowFilteringByColumn="True"
    CellSpacing="0" DataSourceID="SqlDataSource1" GridLines="None" AllowAutomaticDeletes="True"
    AllowAutomaticUpdates="True" AutoGenerateColumns="False" AllowAutomaticInserts="true"
    OnItemDataBound="grdSettlement_ItemDataBound">

.aspx.cs

protected void grdSettlement_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item.IsInEditMode)
    {
        GridEditableItem item = (GridEditableItem)e.Item;
        RadNumericTextBox txtNo = item.FindControl("txtNo") as RadNumericTextBox;
        txtNo.Value = 7;
    }
}
Ankur
  • 519
  • 8
  • 15
0
//protected void grdSettlement_InsertCommand(object source, GridItemEventArgs e)
protected void grdSettlement_InsertCommand(object source, GridCommandEventArgs e)
{
    GridEditableItem ge = e.Item as GridEditableItem;
    if (ge != null)
    {
        //Good way is change TextBox ID 
        TextBox tb = ge["No"].FindControl("No") as TextBox;
        if (tb != null)
        {
            tb.Text = "007";
        }
    }
}

Control does not need to be first.
Try it.

Rafal T
  • 339
  • 1
  • 2
  • 14
  • Error : Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0123: No overload for 'grdSettlement_InsertCommand' matches delegate 'Telerik.Web.UI.GridCommandEventHandler' – Ankur Mar 29 '12 at 15:38
  • Source Error: – Ankur Mar 29 '12 at 15:39
  • My mistake. I did not check whether the EventArgs parameter is correct.protected void grdSettlement_InsertCommand(object source, GridCommandEventArgs e) – Rafal T Mar 30 '12 at 05:34
  • But this is also not working... it's damage the designing of Grid... I want to show "007" number on textbox(ID="No") when I click on "Add New Record"... – Ankur Mar 30 '12 at 15:46
  • Hey Sorry abt wrong comment... It's not Damage the Design there are a little mistake I re write the tag as follow... `` – Ankur Mar 30 '12 at 20:17
  • See I refer this & found that the `OnInsertCommand` is run at the time of submit or Insert the all value which is fill on Insert form... *that Insert form is open after the "Add New Record" click... But I want that event which is pass at the time if "Add New Record" click... – Ankur Mar 30 '12 at 20:37
0

Please check below code snippet.

.aspx

<telerik:GridTemplateColumn DataField="NO" FilterControlAltText="Filter NO column"
                    HeaderText="NO" SortExpression="NO" UniqueName="NO" DataType="System.Int64">
                    <InsertItemTemplate>
                        <telerik:RadNumericTextBox runat="server" ID="txtNo">
                        </telerik:RadNumericTextBox>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <%# Eval("NO") %>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>

.aspx.cs

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {

if (e.Item is GridEditableItem && e.Item.IsInEditMode && e.Item is GridDataInsertItem)
        {
              GridEditableItem item = (GridEditableItem)e.Item;
              RadNumericTextBox txtNo = item.FindControl("txtNo") as RadNumericTextBox;
              txtNo.Value = 7;
        }

}
Jayesh Goyani
  • 11,008
  • 11
  • 30
  • 50