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

OnUpdateCommand

2 Answers 275 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bruno
Top achievements
Rank 1
Bruno asked on 13 Mar 2012, 01:21 PM
Hello, i have a project radGrid editable with user control, similar to that example :
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/usercontroleditform/defaultcs.aspx

My problem is, when i click on update button on my userControl the event on my page which contains my update code, will never be fired.
i want this event above, be fired when i click on the update button on my user control.
protected void rgGrid_UpdateCommand(object sender, GridCommandEventArgs e)
{
    GridEditableItem editedItem = e.Item as GridEditableItem;
    UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
 
 
    //Prepare new row to add it in the DataSource
    DataRow[] changedRows = this.GridSource.Select("codigo = " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["codigo"]);
 
    if (changedRows.Length != 1)
    {
        rgGrid.Controls.Add(new LiteralControl("Unable to locate the Employee for updating."));
        e.Canceled = true;
        return;
    }
 
    //Update new values
    Hashtable newValues = new Hashtable();
 
    newValues["codigo"] = (userControl.FindControl("txtCodigo") as TextBox).Text;
    newValues["descricao"] = (userControl.FindControl("txtDescricao") as TextBox).Text;
    changedRows[0].BeginEdit();
    try
    {
        foreach (DictionaryEntry entry in newValues)
        {
            changedRows[0][(string)entry.Key] = entry.Value;
        }
        changedRows[0].EndEdit();
        this.GridSource.AcceptChanges();
    }
    catch (Exception ex)
    {
        changedRows[0].CancelEdit();
        Window.RadAlert("Erro!", 350, 250, "Mensagem", null);
        e.Canceled = true;
    }
}

user control code
private object _dataItem = null;
 
        protected void Page_Load(object sender, EventArgs e)
        {
 
        }
        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }
 
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
             // should i do something here or what?
        }


Please help me.
Thankz in advance!

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Mar 2012, 01:58 PM
Hello,

Please make sure that you have assigned the commandName for the Update button in the usercontrol edit form for the event bubbling.
It is not actually possible to find the real issue from the given code. Please provide the entire code for further assistance.

-Shinu.
0
Judith
Top achievements
Rank 1
answered on 20 Jul 2018, 07:39 AM
This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. You can use validation controls to verify user input before displaying the input text in a control. ASP.NET provides an input request validation feature to block script and HTML in user input. 
Tags
Grid
Asked by
Bruno
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Judith
Top achievements
Rank 1
Share this question
or