2013-04-03 27 views
0

是否有無法從c#中的RadCombobox中獲取上次選定的值。請指教如何從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 
+0

通過*最後*選擇的值,你的意思是* *當前選擇的值?或者*之前被選中的值?如果沒有選擇任何值會發生什麼? –

+0

嗨科迪,我已經更新了代碼並將值分配給了會話。請參考代碼。謝謝 – Spidey

回答

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