سؤال

Is there anyway to get the last selected value from RadCombobox in c#. Please advise

I did something like this

protected void cboTest_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
Session["CurrentItem"] = e.value;
}

public int GetLastSelectedItem
{
    set { Session["CurrentItem"] = value;}
}

then i need to access the session
int productId = 0;
productId = //need to assigned previous selected radcombo value
هل كانت مفيدة؟

المحلول

Ummar is right, now if you want to do it by applying your code try this:

I reccomend to use ViewState, Session variables are always dificult to handle, also it doesn't have sense if you need it only in that form.

Something like this:

string LastSelectedValue
{
  get { return ViewState["LastSelectedValue"] as string; }
  set { ViewState["LastSelectedValue"] = value; }
}

protected void cboTest_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
    if(string.IsNullOrEmpty(this.LastSelectedValue))
    {
        //This is the first time the user changes the index
    }
    else
    {
        //The last selected Value is stored in this.LastSelectedValue
    }

    // last line of your code must be this one
    this.LastSelectedValue = this.cboTest.SelectedValue;
}

نصائح أخرى

You can try the following code

string old_value = "";
string new_value = "";
protected void cboTest_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
    old_value = e.OldValue;
    new_value = e.Value;
    //do whatever you want with these values
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top