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

RadGrid OnItemCommand remove variables assignment

1 Answer 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hadi
Top achievements
Rank 1
Hadi asked on 30 Jul 2015, 11:24 AM

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;
        }
    }

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 03 Aug 2015, 11:38 AM
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
{
    get
    {
        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.

Regards,
Eyup
Telerik
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
Tags
Grid
Asked by
Hadi
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or