博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Devexpress MVC DropDownList (持续更新))
阅读量:5290 次
发布时间:2019-06-14

本文共 9410 字,大约阅读时间需要 31 分钟。

 

@Html.DevExpress().DropDownEdit(settings =>                                   {                                       settings.Name = "psBankCharge";                                       settings.ControlStyle.Border.BorderColor = System.Drawing.Color.LightGray;                                       settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);                                       settings.Height = System.Web.UI.WebControls.Unit.Pixel(34);                                       settings.ControlStyle.CssClass = "form-control dx-dropdown";                                       settings.Properties.NullText = @Utils.GetTranslation("Select") + " " + @Utils.GetTranslation("Bank Charge");                                       settings.Properties.NullTextStyle.CssClass = ":-moz-placeholder";                                       settings.Properties.DropDownWindowStyle.BackColor = System.Drawing.Color.FromArgb(0xEDEDED);                                       settings.SetDropDownWindowTemplateContent(c =>                                       {                                           @Html.DevExpress().ListBox(                                                   listBoxSettings =>                                                   {                                                       listBoxSettings.Name = "lbBankCharge";                                                       listBoxSettings.ControlStyle.Border.BorderWidth = 0;                                                       listBoxSettings.ControlStyle.BorderBottom.BorderWidth = 1;                                                       listBoxSettings.ControlStyle.Border.BorderColor = System.Drawing.Color.LightGray;                                                       listBoxSettings.ControlStyle.BorderBottom.BorderColor = System.Drawing.Color.FromArgb(0xDCDCDC);                                                       listBoxSettings.Height = System.Web.UI.WebControls.Unit.Pixel(200);                                                       listBoxSettings.Width = System.Web.UI.WebControls.Unit.Percentage(99.99);                                                       listBoxSettings.Properties.SelectionMode = ListEditSelectionMode.CheckColumn;                                                       listBoxSettings.Properties.ClientSideEvents.SelectedIndexChanged = "function(s, e){ ListBoxMultipleSelectionChanged(psBankCharge, s, e);}";                                                       listBoxSettings.Properties.ValueType = typeof(string);                                                       listBoxSettings.Properties.Items.Add("(Select all)");                                                       foreach (ListEditItem item in (System.Collections.IEnumerable)ViewData["BankCharge"])                                                       {                                                           listBoxSettings.Properties.Items.Add(item.Text, item.Value);                                                       }                                                   }                                               ).Render();                                           ViewContext.Writer.Write("
"); @Html.DevExpress().Button( buttonSettings => { buttonSettings.Name = "btnCloseBankCharge"; buttonSettings.Text = "Close"; buttonSettings.ControlStyle.CssClass = "btn btn-default"; buttonSettings.ClientSideEvents.Click = "function(s, e){ psBankCharge.HideDropDown(); }"; } ).Render(); ViewContext.Writer.Write("
"); }); settings.DisabledStyle.BackColor = System.Drawing.Color.FromArgb(0xEEEEEE); settings.Properties.AnimationType = DevExpress.Web.AnimationType.None; settings.Properties.ClientSideEvents.TextChanged = "function(s, e){ SynchronizeListBoxMultipleValues(s, lbBankCharge); }"; settings.Properties.ClientSideEvents.DropDown = "function(s, e){ SynchronizeListBoxMultipleValues(s, lbBankCharge); }"; }).GetHtml()

  

//选中指定的Item, 

SelectItemByValue(cboModalDepCode,lboModalDepCode,Value);

全部取消选中(多选)

ResetListBox(cboSearchDepCode, lboSearchDepCode);

全部取消选中(单选)

 ResetSingleListBox(cboSearchDateOption,lboSearchDateOption);

获取选中的值(单选)

GetValuesByTexts(GetSelectedItemsText_Single(lboModalPackType.GetSelectedItems()), lboModalPackType);

获取选中的值(多选)

GetValuesByTexts(GetSelectedItemsText(lbBraCode.GetSelectedItems()).split(gs_TextSeparator),lbBraCode)

 

 

var gs_TextSeparator = ",";function UpdateSelectAllItemState(ao_lbListBox) {    IsAllSelected(ao_lbListBox) ? ao_lbListBox.SelectIndices([0]) : ao_lbListBox.UnselectIndices([0]);}function IsAllSelected(ao_lbListBox) {    for (var i = 1; i < ao_lbListBox.GetItemCount() ; i++)        if (!ao_lbListBox.GetItem(i).selected)            return false;    return true;}function UpdateText(ao_lbListBox, ao_ddlDropDown, ab_IsSingle) {    if (ab_IsSingle)        ao_ddlDropDown.SetText(GetSelectedItemsText_Single(ao_lbListBox.GetSelectedItems()));    else        ao_ddlDropDown.SetText(GetSelectedItemsText(ao_lbListBox.GetSelectedItems()));}function GetSelectedItemsText(aa_Items) {    var la_Texts = [];    for (var i = 0; i < aa_Items.length; i++)        if (aa_Items[i].index != 0)            la_Texts.push(aa_Items[i].text);    return la_Texts.join(gs_TextSeparator);}function GetSelectedItemsText_Single(aa_Items) {    var la_Texts = [];    for (var i = 0; i < aa_Items.length; i++)        la_Texts.push(aa_Items[i].text);    return la_Texts;}function GetValuesByTexts(aa_Text, ao_lbListBox) {    var la_ActualTexts = [];    var ls_Item;    for (var i = 0; i < aa_Text.length; i++) {        ls_Item = ao_lbListBox.FindItemByText(aa_Text[i]);        if (ls_Item != null) {            la_ActualTexts.push( ls_Item.value );        } else {            la_ActualTexts.push("");        }    }    return la_ActualTexts;}function GetQuotesValuesByTexts(aa_Text, ao_lbListBox,as_Quotes) {    var la_ActualTexts = [];    var ls_Item;    for (var i = 0; i < aa_Text.length; i++) {        ls_Item = ao_lbListBox.FindItemByText(aa_Text[i]);        if (ls_Item != null) {            la_ActualTexts.push(as_Quotes + ls_Item.value + as_Quotes);        } else {            la_ActualTexts.push("");        }    }    return la_ActualTexts;}function GetTextsByValues(aa_Value, ao_lbListBox) {    var la_ActualTexts = [];    var ls_Item;    for (var i = 0; i < aa_Value.length; i++) {        ls_Item = ao_lbListBox.FindItemByValue(aa_Value[i]);        if (ls_Item !== null)            la_ActualTexts.push(ls_Item.text);    }    return la_ActualTexts;}function SelectItemByValue(ao_ddlDropDown, ao_lbListBox, as_Value) {    for (var i = 0; i < ao_lbListBox.GetItemCount() ; i++) {        if (ao_lbListBox.GetItem(i).value == as_Value) {            ao_lbListBox.SetSelectedIndex(i);            break;        }    }    UpdateText(ao_lbListBox, ao_ddlDropDown, true);}function SetSelectItemByText(ao_ddlDropDown, ao_lbListBox, as_Text) {    for (var i = 0; i < ao_lbListBox.GetItemCount() ; i++) {        if (ao_lbListBox.GetItem(i).text == as_Text) {            ao_lbListBox.SetSelectedIndex(i);            break;        }    }    UpdateText(ao_lbListBox, ao_ddlDropDown, true);}function SynchronizeListBoxValues(ao_ddlDropDown, ao_lbListBox) {    var la_Texts = ao_ddlDropDown.GetText().split(gs_TextSeparator);    var la_Values = GetValuesByTexts(la_Texts, ao_lbListBox);    ao_lbListBox.SelectValues(la_Values);    UpdateText(ao_lbListBox, ao_ddlDropDown, true);}function ListBoxSelectionChanged(ao_ddlDropDown, ao_lbListBox) {    UpdateText(ao_lbListBox, ao_ddlDropDown, true);    ao_ddlDropDown.HideDropDown();}function InitDropDown(ao_ddlDropDown, ao_lbListBox) {    ao_lbListBox.SetSelectedIndex(0);    UpdateText(ao_lbListBox, ao_ddlDropDown, true);}function ListBoxMultipleSelectionChanged(ao_ddlDropDown, ao_lbListBox, ao_lbListBoxEvent) {    if (ao_lbListBoxEvent.index === 0)        ao_lbListBoxEvent.isSelected ? ao_lbListBox.SelectAll() : ao_lbListBox.UnselectAll();    UpdateSelectAllItemState(ao_lbListBox);    UpdateText(ao_lbListBox, ao_ddlDropDown, false);}function SynchronizeListBoxMultipleValues(ao_ddlDropDown, ao_lbListBox) {    ao_lbListBox.UnselectAll();    var la_Texts = ao_ddlDropDown.GetText().split(gs_TextSeparator);    var la_Values = GetValuesByTexts(la_Texts, ao_lbListBox);    ao_lbListBox.SelectValues(la_Values);    UpdateSelectAllItemState(ao_lbListBox);    UpdateText(ao_lbListBox, ao_ddlDropDown, false);}function ResetListBox(ao_ddlDropDown, ao_lbListBox) {    ao_lbListBox.UnselectAll();    ao_ddlDropDown.SetText(null);}function ResetSingleListBox(ao_ddlDropDown, ao_lbListBox) {    ao_lbListBox.SetSelectedIndex(0);    UpdateText(ao_lbListBox, ao_ddlDropDown, true);}

  

转载于:https://www.cnblogs.com/hesijian/p/9809368.html

你可能感兴趣的文章
1_fbauto
查看>>
IO体系、集合体系、多线程、jdbc
查看>>
关于时间:UTC/GMT/xST/ xDT
查看>>
[51Nod1089] 最长回文子串 V2(Manacher算法)
查看>>
Asp.Net生命周期系列六
查看>>
php引用 =& 详解
查看>>
Codeforces 914D Bash and a Tough Math Puzzle (ZKW线段树)
查看>>
POJ 3009: Curling 2.0
查看>>
DLNA介绍(包含UPnP,2011/6/20 更新)
查看>>
ANGULARJS5从0开始(2) - 整合bootstrap和font-awesome
查看>>
Android 使用Parcelable序列化对象
查看>>
Python Web框架Django (零)
查看>>
Foxmail出现 错误信息:553 mailbox not found怎么解决
查看>>
spring_远程调用
查看>>
js 中基本数据类型和引用数据类型 ,,,, js中对象和函数的关系
查看>>
登录服务器,首先用到的5个命令
查看>>
多米诺骨牌
查看>>
区间DP 等腰三角形
查看>>
mysql 存储引擎对索引的支持
查看>>
Linq 学习(1) Group & Join--网摘
查看>>