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

RadGrid1_UpdateCommand not firing

2 Answers 144 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ajay
Top achievements
Rank 1
Ajay asked on 19 Jul 2010, 11:05 AM
Hi,

I am trying to update a record using RADGrid, but the RadGrid1_UpdateCommand event is not firing, I am using in-place edit mode
On click of the edit icon the row gets converted into edit mode and RadGrid1_EditCommand event is fired, but after chaging the values the breakpoint never executes the RadGrid1_UpdateCommand event.

My code is below:

 

 

 

 

<telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" PageSize="10" AllowPaging="True" AllowSorting="true" OnNeedDataSource="RadGrid1_NeedDataSource" AutoGenerateColumns="False" AllowAutomaticUpdates="True" OnItemUpdated="RadGrid1_ItemUpdated"OnUpdateCommand="RadGrid1_UpdateCommand" OnEditCommand="RadGrid1_EditCommand"OnItemDeleted="RadGrid1_ItemDeleted" OnItemInserted="RadGrid1_ItemInserted" OnDataBound="RadGrid1_DataBound" OnDeleteCommand="RadGrid1_DeleteCommand" onitemcommand="RadGrid1_ItemCommand" >

 

<PagerStyle Mode="NextPrevAndNumeric" />

 

<MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataKeyNames="slno"

HorizontalAlign="NotSet" AutoGenerateColumns="False" EditMode="InPlace" >

 

<Columns>

 

<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">

 

<ItemStyle CssClass="MyImageButton" />

 

</telerik:GridEditCommandColumn>

 

<telerik:GridBoundColumn DataField="slno" HeaderText="Id" SortExpression="slno"

UniqueName="slno">

 

</telerik:GridBoundColumn>

 

<telerik:GridBoundColumn DataField="cData" HeaderText="Data" SortExpression="cData" UniqueName="cData" ColumnEditorID="GridTextBoxColumnEditor1">

 

</telerik:GridBoundColumn>

 

<telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">

 

<ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />

</telerik:GridButtonColumn>

 

</Columns>

 

<EditFormSettings ColumnNumber="1" CaptionDataField="LoginName" CaptionFormatString="Edit details of Customer {0}">

 

<FormTableItemStyle Wrap="False"></FormTableItemStyle>

 

<FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>

 

<FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White" Width="100%" />

 

<FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" BackColor="White" />

 

<FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>

 

<EditColumn ButtonType="ImageButton" InsertText="Insert Order" UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit">

 

</EditColumn>

 

<FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>

 

</EditFormSettings>

 

</MasterTableView>

 

<ClientSettings>

<ClientEvents OnRowDblClick="RowDblClick" />

</ClientSettings>

 

</telerik:RadGrid>

 

<telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server" TextBoxStyle-Width="40px" />

 

<telerik:RadWindowManager ID="RadWindowManager1" runat="server"></telerik:RadWindowManager>

 

 

 

DataSet ds;

    SqlDataAdapter da;

    SqlConnection conn;

 

    string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

 

    protected void Page_Load(object sender, EventArgs e)

    {

        //if (Page.IsPostBack == false)

        //{

        //fillData();

        //}

        //RadGrid1.UpdateCommand += new GridCommandEventHandler(RadGrid1_UpdateCommand);

    }

 

    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)

    {

        fillData();

    }

 

    protected void fillData()

    {

        conn = new SqlConnection(connStr);

        ds = new DataSet();

        da = new SqlDataAdapter("select * from tblData", conn);

        da.Fill(ds, "customerMast");

 

        ds.Tables[0].PrimaryKey = new DataColumn[] {ds.Tables[0].Columns["slno"]};

 

        //RadGrid1.MasterTableView.DataSource = ds.Tables[0];

        RadGrid1.DataSource = ds.Tables[0];

    }

 

    protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)

    {

        GridEditableItem item = (GridEditableItem)e.Item;

        String id = item.GetDataKeyValue("CustId").ToString();

 

        if (e.Exception != null)

        {

            e.KeepInEditMode = true;

            e.ExceptionHandled = true;

            SetMessage("Customer with ID " + id + " cannot be updated. Reason: " + e.Exception.Message);

        }

        else

        {

            SetMessage("Customer with ID " + id + " is updated!");

        }

 

    }

 

    protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e)

    {

        if (e.Exception != null)

        {

            e.ExceptionHandled = true;

            SetMessage("Customer cannot be inserted. Reason: " + e.Exception.Message);

        }

        else

        {

            SetMessage("New Customer is inserted!");

        }

    }

 

    protected void RadGrid1_ItemDeleted(object source, GridDeletedEventArgs e)

    {

        GridDataItem dataItem = (GridDataItem)e.Item;

        String id = dataItem.GetDataKeyValue("slno").ToString();

 

        if (e.Exception != null)

        {

            e.ExceptionHandled = true;

            SetMessage("Customer with ID " + id + " cannot be deleted. Reason: " + e.Exception.Message);

        }

        else

        {

            SetMessage("Customer with ID " + id + " is deleted!");

        }

    }

    private void DisplayMessage(string text)

    {

        RadGrid1.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", text)));

    }

 

    private void SetMessage(string message)

    {

        gridMessage = message;

    }

 

    private string gridMessage = null;

    protected void RadGrid1_DataBound(object sender, EventArgs e)

    {

        if (!string.IsNullOrEmpty(gridMessage))

        {

            DisplayMessage(gridMessage);

        }

    }

 

    protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)

    {

        //Occurs when the Update button is clicked for an item in the Telerik RadGrid control.

 

        GridDataItem dataItem = (GridDataItem)e.Item;

        String id = dataItem.GetDataKeyValue("ProductID").ToString();

        DisplayMessage("update " + id);

    }

 

    protected void RadGrid1_EditCommand(object source, GridCommandEventArgs e)

    {

        //Occurs when the Edit button is clicked for an item in the Telerik RadGrid control.

 

        GridDataItem dataItem = (GridDataItem)e.Item;

        String id = dataItem["slno"].Text;

        //String id = dataItem.GetDataKeyValue("ProductID").ToString();

        DisplayMessage("want to update " + id);

    }

 

    protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e)

    {

        GridDataItem dataItem = (GridDataItem)e.Item;

        String id = dataItem["slno"].Text;

        String idName = dataItem["cData"].Text;

        //String id = dataItem.GetDataKeyValue("ProductID").ToString();

       

        clsMethods objCls = new clsMethods();

        objCls.executeDBQuery("delete from tblData where slno = " + id);

 

        DisplayMessage("Deleted " + idName);

 

        fillData();

 

    }

 

    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)

    {

        if (e.CommandName == "Update")

        {

            GridDataItem dataItem = (GridDataItem)e.Item;

            String id = dataItem["slno"].Text;

            DisplayMessage("update " + id);

        }

 

    }

2 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetoslav
Telerik team
answered on 20 Jul 2010, 04:29 PM
Hello Ajay,

Tha'ts a strange behavior. Could you paste your entire code-behind and aspx. Do use the code-formatter tool of the ticket editor. Thanks.

Regards,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ajay
Top achievements
Rank 1
answered on 21 Jul 2010, 07:28 AM
Hi,

I got this issue solved.

I was using the RADGrid inside the RadDockLayout, evetually the ViewState of RadDockLayout was set to False.
Setting the ViewState of RadDockLayout to True solved the things.

Thank you for your attention and time,

Ajay
Tags
Grid
Asked by
Ajay
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Ajay
Top achievements
Rank 1
Share this question
or