RadGrid OnItemCommand remove variables assignment

2 posts, 0 answers
  1. Hadi
    Hadi avatar
    1 posts
    Member since:
    Nov 2014

    Posted 30 Jul 2015 Link to this post

    I create string variable "onEditUser" to be filled with a cell value (Label) when "Edit" command is fired. It is assigned correctly when The Edit button is clicked but when OnItemCommand() is recalled to perform Update Command, the variable assignment is removed and onEditUser become null.

    Is there any help why this occurs, and what is the solution? (I need to use this variable in another method)

    public partial class EditUsers : System.Web.UI.Page
    string onEditUser;
        public void GridItemCommand(object sender, GridCommandEventArgs e)
            if (e.CommandName == RadGrid.UpdateCommandName || e.CommandName == RadGrid.PerformInsertCommandName)
                GridEditableItem item = e.Item as GridEditableItem;
                RadComboBox userTypecombo = (RadComboBox)item.FindControl("UserTypeRadComboBox");
                string userType = userTypecombo.SelectedItem.Text;
                SqlDataSource1.InsertParameters["UserType"].DefaultValue = userType;
                SqlDataSource1.UpdateParameters["UserType"].DefaultValue = userType;
            if (e.CommandName == RadGrid.EditCommandName)
            GridItem item = e.Item;
            Label userNameLB = (Label)item.FindControl("UserNameLabel");
            onEditUser = userNameLB.Text;

  2. Eyup
    Eyup avatar
    3699 posts

    Posted 03 Aug 2015 Link to this post

    Hello Hadi,

    If you are declaring the onEditUser variable in the global scope, it will be reset an every postback and AJAX request. You can define a property to keep it - similar to the following snippet, just replace te List<int> with string:
    public List<int> DeletedIDs
            if (Session["DeletedIDs"] == null)
                Session["DeletedIDs"] = new List<int>();
            return (List<int>)Session["DeletedIDs"];

    Hope this helps. Please give it a try and let me know about the result.

    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 Feedback Portal and vote to affect the priority of the items
Back to Top