作成日: 2019/04/03 最終更新日: 2019/04/03
文書種別
使用方法
詳細
ComboBoxのOnClientSelectedIndexChangedプロパティを使用してイベントを実装し、selectedIndexの値を取得してlocalStorageに格納した上で、この値をページロード時にComboBoxに再設定します。
これにより、ComboBoxで任意の項目を選択した状態でページ遷移後、元のページに戻った際、ComboBoxの項目の選択状態を復元することができます。
◎サンプルコード(View)
これにより、ComboBoxで任意の項目を選択した状態でページ遷移後、元のページに戻った際、ComboBoxの項目の選択状態を復元することができます。
◎サンプルコード(View)
<script>
onload = function () {
var ctl = wijmo.Control.getControl("#ComboBox1");
var comboIndex = localStorage.getItem("ComboBoxIndex");
if (comboIndex && comboIndex.selectedIndex !==0) {
ctl.selectedIndex = parseInt(comboIndex);
}
}
function SelectedIndexChanged(s, e) {
if (document.activeElement===s.inputElement) {
localStorage.setItem("ComboBoxIndex", s.selectedIndex);
}
}
</script>
@(Html.C1().ComboBox().Id("ComboBox1")
.Bind(Model)
.DisplayMemberPath("Name").SelectedValuePath("ID")
.OnClientSelectedIndexChanged("SelectedIndexChanged")
)
onload = function () {
var ctl = wijmo.Control.getControl("#ComboBox1");
var comboIndex = localStorage.getItem("ComboBoxIndex");
if (comboIndex && comboIndex.selectedIndex !==0) {
ctl.selectedIndex = parseInt(comboIndex);
}
}
function SelectedIndexChanged(s, e) {
if (document.activeElement===s.inputElement) {
localStorage.setItem("ComboBoxIndex", s.selectedIndex);
}
}
</script>
@(Html.C1().ComboBox().Id("ComboBox1")
.Bind(Model)
.DisplayMemberPath("Name").SelectedValuePath("ID")
.OnClientSelectedIndexChanged("SelectedIndexChanged")
)
旧文書番号
83816