0

无论如何要从 C# 中的 RadCombobox 获取最后选择的值。请指教

我做了这样的事情

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
4

2 回答 2

0

你可以试试下面的代码

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
}
于 2013-04-03T13:01:10.833 回答
0

Ummar 是对的,现在如果你想通过应用你的代码来做到这一点,试试这个:

我建议使用 ViewState,Session 变量总是很难处理,如果你只需要这种形式,它也没有意义。

像这样的东西:

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;
}
于 2013-04-03T13:17:18.933 回答