MultiCombo控件多选突然失效问题

MultiCombo控件多选突然不能多选了,在出现这一问题之前一切正常,可是怎么检查都觉得没问题,后来不经意间发现了问题的所在,现将代码贴出:

前端代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Admin.aspx.cs" Inherits="Admin"
MasterPageFile="~/Site.master" %>


<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="QueryCondition" runat="server" ContentPlaceHolderID="QueryCondition">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<style type="text/css">
.toolbar
{
background-color:#3a4f63;
}</style>
<ext:Panel ID="Panel1" runat="server" BodyCssClass="toolbar"><Content>
<div class="menu">
<table style="text-align: center;width:940px;">
<tr>
<td style="width:70px;"><b>StartDate:</b></td>
<td style="width:120px;">
<ext:DateField ID="StartDate" runat="server" AnchorHorizontal="100%" FieldLabel="" Editable="false" EmptyText="Please Select..." Vtype="daterange" Width="120px" LabelWidth="0">
<CustomConfig>
<ext:ConfigItem Mode="Value" Name="EndDate" Value="#{EndDate}" />
</CustomConfig>
</ext:DateField>
</td>
<td style="width:60px;"><b>EndDate:</b></td>
<td style="width:120px;">
<ext:DateField ID="EndDate" runat="server" AnchorHorizontal="100%" FieldLabel="" Editable="false" EmptyText="Please Select..." Vtype="daterange" Width="120px" LabelWidth="0">
<CustomConfig>
<ext:ConfigItem Mode="Value" Name="StartDate" Value="#{StartDate}" />
</CustomConfig>
</ext:DateField>
</td>
<td style="width:28px;"><b>User:</b></td>
<td style="width:140px;">
<ext:MultiCombo ID="SelectUsers" runat="server" FieldLabel="" LabelWidth="0"
ValueField="emp_info_id" Editable="false" EmptyText="Please Select..." DisplayField="emp_info_name"
Width="140px">
<Store>
<ext:Store runat="server" ID="selectUser">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="emp_info_id" Type="String">
</ext:RecordField>
<ext:RecordField Name="emp_info_name" Type="String">
</ext:RecordField>
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
<AutoEl Tag="Select">
</AutoEl>
<Triggers>
<ext:FieldTrigger Tag="selectAll" Icon="SimplePlus" Qtip="Select all" />
<ext:FieldTrigger Tag="unselectAll" Icon="SimpleMinus" Qtip="Unselect all" />
</Triggers>
<Listeners>
<TriggerClick Handler="if(tag == 'selectAll')
{
this.selectAll();
this.setRawValue('All are selected');
}
if(tag=='unselectAll')
{
this.clearSelections();
this.setRawValue('All are unselected');
}" />
</Listeners>
</ext:MultiCombo>
</td>
<td style="width:50px;"><b>CoCode:</b></td>
<td style="width:110px;">
<ext:MultiCombo ID="CoCode_MC" runat="server"
ValueField="case_info_id" Editable="false" EmptyText="Please Select..." DisplayField="case_info_description"
Width="110px">
<Store>
<ext:Store runat="server" ID="CoCode">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="case_info_id" Type="String">
</ext:RecordField>
<ext:RecordField Name="case_info_description" Type="String">
</ext:RecordField>
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
<AutoEl Tag="Select">
</AutoEl>
<Triggers>
<ext:FieldTrigger Tag="selectAll" Icon="SimplePlus" Qtip="Select all" />
<ext:FieldTrigger Tag="unselectAll" Icon="SimpleMinus" Qtip="Unselect all" />
</Triggers>
<Listeners>
<TriggerClick Handler="if(tag == 'selectAll')
{
this.selectAll();
this.setRawValue('All are selected');
}
if(tag=='unselectAll')
{
this.clearSelections();
this.setRawValue('All are unselected');
}" />
</Listeners>
</ext:MultiCombo>
</td>
<td style="width:80px;"><b>AuditStatus:</b></td>
<td style="width:110px;">
<ext:ComboBox ID="Audit_SC" runat="server" FieldLabel="" LabelWidth="0" ValueField="Value"
EmptyText="Please Select..." Width="110px" Height="22px" DisplayField="Text" Editable="false">
<Store>
<ext:Store runat="server" ID="Store1">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="Text" Type="String">
</ext:RecordField>
<ext:RecordField Name="Value" Type="String">
</ext:RecordField>
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
<Items>
<ext:ListItem Text="Pending" Value="0" />
<ext:ListItem Text="Audited" Value="1" />
<ext:ListItem Text="Rejected" Value="2" />
<ext:ListItem Text="Draft" Value="3" />
</Items>
</ext:ComboBox>
<%--<asp:DropDownList ID="MainActivities" runat="server" Width="200px" DataValueField="case_info_id"
DataTextField="case_info_description">
</asp:DropDownList>--%>
</td>
</tr>
</table>
<table style="text-align: center;width:940px;">
<tr>
<td style="width:60px;"><b>Function:</b></td>
<td>
<ext:MultiCombo ID="Function_MC" runat="server" FieldLabel="" LabelWidth="0" ValueField="case_info_id"
Editable="false" EmptyText="Please Select..." Width="130px" Height="22px" DisplayField="case_info_description">
<Store>
<ext:Store runat="server" ID="Function">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="case_info_id" Type="String">
</ext:RecordField>
<ext:RecordField Name="case_info_description" Type="String">
</ext:RecordField>
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
<AutoEl Tag="Select">
</AutoEl>
<Triggers>
<ext:FieldTrigger Tag="selectAll" Icon="SimplePlus" Qtip="Select all" />
<ext:FieldTrigger Tag="unselectAll" Icon="SimpleMinus" Qtip="Unselect all" />
</Triggers>
<Listeners>
<TriggerClick Handler="if(tag == 'selectAll')
{
this.selectAll();
this.setRawValue('All are selected');
}
if(tag=='unselectAll')
{
this.clearSelections();
this.setRawValue('All are unselected');
}" />
</Listeners>
</ext:MultiCombo>
<%--<asp:DropDownList ID="Function" runat="server" Width="120px" DataValueField="case_info_id"
DataTextField="case_info_description" AutoPostBack="True" Height="22px" OnTextChanged="Function_TextChanged">
</asp:DropDownList>--%>
</td>
<td style="width:85px;"><b>ProcessName:</b></td>
<td>
<ext:MultiCombo ID="ProcessName_MC" runat="server" FieldLabel="" LabelWidth="0" ValueField="case_info_id"
Editable="false" EmptyText="Please Select..." Width="195px" Height="22px" DisplayField="case_info_description">
<Store>
<ext:Store runat="server" ID="ProcessName">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="case_info_id" Type="String">
</ext:RecordField>
<ext:RecordField Name="case_info_description" Type="String">
</ext:RecordField>
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
<AutoEl Tag="Select">
</AutoEl>
<Triggers>
<ext:FieldTrigger Tag="selectAll" Icon="SimplePlus" Qtip="Select all" />
<ext:FieldTrigger Tag="unselectAll" Icon="SimpleMinus" Qtip="Unselect all" />
</Triggers>
<Listeners>
<TriggerClick Handler="if(tag == 'selectAll')
{
this.selectAll();
this.setRawValue('All are selected');
}
if(tag=='unselectAll')
{
this.clearSelections();
this.setRawValue('All are unselected');
}" />
</Listeners>
</ext:MultiCombo>
<%--<asp:DropDownList ID="ProcessName" runat="server" Width="200px" DataValueField="case_info_id"
DataTextField="case_info_description" AutoPostBack="True" OnTextChanged="ProcessName_TextChanged">
</asp:DropDownList>--%>
</td>
<td style="width:90px;"><b>MainActivities:</b></td>
<td>
<ext:MultiCombo ID="MainActivities_MC" runat="server" FieldLabel=""
LabelWidth="0" ValueField="case_info_id" Editable="false" EmptyText="Please Select..."
Width="235px" Height="22px" DisplayField="case_info_description">
<Store>
<ext:Store runat="server" ID="MainActivities">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="case_info_id" Type="String">
</ext:RecordField>
<ext:RecordField Name="case_info_description" Type="String">
</ext:RecordField>
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
<AutoEl Tag="Select">
</AutoEl>
<Triggers>
<ext:FieldTrigger Tag="selectAll" Icon="SimplePlus" Qtip="Select all" />
<ext:FieldTrigger Tag="unselectAll" Icon="SimpleMinus" Qtip="Unselect all" />
</Triggers>
<Listeners>
<TriggerClick Handler="if(tag == 'selectAll')
{
this.selectAll();
this.setRawValue('All are selected');
}
if(tag=='unselectAll')
{
this.clearSelections();
this.setRawValue('All are unselected');
}" />
</Listeners>
</ext:MultiCombo>
<%--<asp:DropDownList ID="MainActivities" runat="server" Width="200px" DataValueField="case_info_id"
DataTextField="case_info_description">
</asp:DropDownList>--%>
</td>
<td style="text-align: center">
<span style="display: inline"><asp:Button ID="btnQuery" runat="server" Width="50px" Text="Query" ToolTipType="Qtip" ToolTip="Query" OnClick="btnQuery_Click" />
<asp:Button ID="btnClear" runat="server" Width="50px" Text="Clear" ToolTipType="Qtip" ToolTip="Clear all query condition"
OnClick="btnClear_Click" /></span>
</td>
</tr>
</table>
</div></Content></ext:Panel>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<style type="text/css">
.collumename
{
font-weight: bold;
text-align: center;
}


.style3
{
width: 93px;
text-align: center;
}
.style5
{
width: 74px;
}
.style6
{
width: 160px;
}
.style7
{
width: 126px;
}
.maincontent
{
background-color:#e3e3e3;
}
</style>
<div style="width: 100%;">
<div class="menu">
</div>
<%-- <ext:Panel ID="Panel2" runat="server" BodyCssClass="maincontent"><Content>--%>
<div id="result" style="background: #e3e3e3;">
<asp:GridView ID="GridView1" runat="server" Width="100%" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="Vertical">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="eci_start_date" HeaderText="Date" />
<asp:BoundField DataField="emp_info_name" HeaderText="UserName" />
<asp:BoundField DataField="eci_function" HeaderText="Function" />
<asp:BoundField DataField="eci_process_name" HeaderText="ProcessName" />
<asp:BoundField DataField="eci_main_activities" HeaderText="Main Activities" />
<asp:BoundField DataField="eci_cocode" HeaderText="CoCode" />
<asp:BoundField DataField="eci_displayhours" HeaderText="Hours" />
<asp:BoundField DataField="eci_remark" HeaderText="Remark" />
<asp:BoundField DataField="eci_auditresult" HeaderText="Status" />
<asp:BoundField DataField="eci_comment" HeaderText="Comment" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" ForeColor="White" VerticalAlign="NotSet"
HorizontalAlign="NotSet" Font-Bold="True" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
VerticalAlign="Middle" HorizontalAlign="Center" />
<PagerStyle BackColor="#284775" ForeColor="White" VerticalAlign="NotSet"
HorizontalAlign="NotSet" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" VerticalAlign="NotSet"
HorizontalAlign="NotSet" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"
VerticalAlign="NotSet" HorizontalAlign="NotSet" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</div>
<div style="width: 880px; margin-top: 20px; margin-bottom:50px;">
<div style="float: left; color: Red;">
<asp:Label ID="Label1" runat="server" Text=""></asp:Label></div>
<div style="float: right;">
<asp:LinkButton ID="btnExport" runat="server" Text="Export To Excel File" OnClick="btnExport_Click" />&nbsp;&nbsp;&nbsp;&nbsp;
<asp:LinkButton ID="btnReturn" runat="server" Text="Return" OnClick="btnReturn_Click"
Visible="true" />
</div>
</div>
<%-- </Content></ext:Panel>--%>
</div>
</asp:Content>

后台代码是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XianHe.BLL;
using XianHe.Model;
using System.Text;
using Ext.Net;
using System.Web.UI.HtmlControls;


public partial class Admin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//string strAbsolutePath = Request.ApplicationPath + "/User.aspx";
//if (Request.UrlReferrer.AbsolutePath == strAbsolutePath)


if (!IsPostBack)
{
if (Session["Account"] == null)
{
Response.Redirect("Account/Login.aspx");
btnReturn.Visible = true;
}
//DateField1.SetValue(DateTime.Now.ToString("YYYY/MM/dd"));
//DateField1.Value = DateTime.Now.ToString("YYYY/MM/dd");
}
Bind();
}
public void Bind()
{
if (Session["UserLoginID"] == null)
Response.Redirect("Account/Login.aspx");
//data bind for User
emp_infoBLL eibll = new emp_infoBLL();
IList<emp_infoInfo> eiiinfos = eibll.GetAll();
emp_infoInfo info = eibll.GetById(Session["UserLoginID"].ToString());
if (info.emp_info_role == "0")
selectUser.DataSource = eiiinfos.Select(s =>
(new { emp_info_id = s.emp_info_id, emp_info_name = s.emp_info_name })).
Where(f => (f.emp_info_id == Session["UserLoginID"].ToString())).ToList();
else
{
selectUser.DataSource = eiiinfos.
Where(item => (item.emp_info_bossid == Session["UserLoginID"].ToString())).Select(s =>
(new { emp_info_id = s.emp_info_id, emp_info_name = s.emp_info_name }));
}
selectUser.DataBind();


//data bind for CoCode
case_infoBLL cibll = new case_infoBLL();
IList<case_infoInfo> cinfos = cibll.GetAll();
CoCode.DataSource = cinfos.Where(c => c.case_info_type == "CoCode").ToList().
Select(s => new { case_info_id = s.case_info_id.Trim(), case_info_description = s.case_info_description });//trim(),else can't select
CoCode.DataBind();


//data bind for Function
Function.DataSource = cinfos.Where(c => c.case_info_crose == 1).ToList().
Select(s => new { case_info_id = s.case_info_id.Trim(), case_info_description = s.case_info_description });
Function.DataBind();


//data bind for ProcessName
ProcessName.DataSource = cinfos.Where(c => c.case_info_crose == 2).ToList().
Select(s => new { case_info_id = s.case_info_id.Trim(), case_info_description = s.case_info_description });
ProcessName.DataBind();


//data bind for MainActivities
MainActivities.DataSource = cinfos.Where(c => c.case_info_crose == 3).ToList().
Select(s => new { case_info_id = s.case_info_id.Trim(), case_info_description = s.case_info_description });//.
//Select(s => new { case_info_id = s.case_info_id, case_info_description = s.case_info_description });
MainActivities.DataBind();


data bind for gridview
//string userid = "EMP0000001";
//emp_case_infoBLL ecibll = new emp_case_infoBLL();
//IList<emp_case_Info> eciInfos = ecibll.GetAll(userid);
//GridView1.DataSource = eciInfos;
//GridView1.DataBind();


}




//protected void Function_TextChanged(object sender, EventArgs e)
//{
// case_infoBLL cibll = new case_infoBLL();
// IList<case_infoInfo> cinfos = cibll.GetAll();
// //data bind for ProcessName
// ProcessName.DataSource = cinfos.Where(c => c.case_info_type == Function.SelectedItem.Value).ToList();//.
// //Select(s => new { case_info_id = s.case_info_id, case_info_description = s.case_info_description });
// ProcessName.DataBind();
//}


//protected void ProcessName_TextChanged(object sender, EventArgs e)
//{
// case_infoBLL cibll = new case_infoBLL();
// IList<case_infoInfo> cinfos = cibll.GetAll();
// //data bind for MainActivities
// MainActivities.DataSource = cinfos.Where(c => c.case_info_type == ProcessName.SelectedItem.Value).ToList();//.
// //Select(s => new { case_info_id = s.case_info_id, case_info_description = s.case_info_description });
// MainActivities.DataBind();
//}
protected void btnReturn_Click(object sender, EventArgs e)
{
Response.Redirect("User.aspx");
}
protected void btnQuery_Click(object sender, EventArgs e)
{
if (Session["UserLoginID"] == null || String.IsNullOrEmpty(Session["UserLoginID"].ToString()))
Response.Redirect("Account/Login.aspx");
if (String.IsNullOrEmpty(StartDate.Text) || StartDate.Text.Equals("0001/1/1 0:00:00") ||
String.IsNullOrEmpty(EndDate.Text) || EndDate.Text.Equals("0001/1/1 0:00:00"))
{
ExtMessage(MessageBox.Icon.INFO, "Information", "Please select date...");
return;
}
string strStartDate = StartDate.Text;
string strEndDate = EndDate.Text;
string strSelectUsers = GetStringCheckedItem(SelectUsers);
string strCoCodes = GetStringCheckedItem(CoCode_MC);
string strFunctions = GetStringCheckedItem(Function_MC);
string strProcessNames = GetStringCheckedItem(ProcessName_MC);
string strMainActivities = GetStringCheckedItem(MainActivities_MC);
string strAudit = Audit_SC.SelectedItem.Value;
emp_case_infoBLL bll = new emp_case_infoBLL();
if (Request.QueryString["search"] == "1")
{
strSelectUsers = "''" + Session["UserLoginID"].ToString() + "''";
}
else
{
strSelectUsers = GetStringCheckedItem(SelectUsers);
}
IList<emp_case_Info> eciInfos = bll.GetAll(strStartDate, strEndDate, strSelectUsers, strCoCodes, strFunctions, strProcessNames, strMainActivities, strAudit);
if (eciInfos.Count == 0)
ExtMessage(MessageBox.Icon.INFO, "Information", "No data");
foreach (emp_case_Info item in eciInfos)
{
item.eci_displayhours = String.Format("{0}H", (1.0 * item.eci_total_minute / 60));
}
GridView1.DataSource = eciInfos;
GridView1.DataBind();
}
protected void btnClear_Click(object sender, EventArgs e)
{
StartDate.SelectedValue = String.Empty;
EndDate.SelectedValue = String.Empty;
SelectUsers.SelectedItems.Clear();
CoCode_MC.SelectedItems.Clear();
Audit_SC.SelectedIndex = -1;
Audit_SC.SelectedItem.Value = String.Empty;// SelectedIndex = -1;
Function_MC.SelectedItems.Clear();
ProcessName_MC.SelectedItems.Clear();
MainActivities_MC.SelectedItems.Clear();
}
private void ExtMessage(MessageBox.Icon icon, string Title, string Content)
{
Ext.Net.MessageBox alert = new Ext.Net.MessageBox();
Ext.Net.MessageBoxConfig config = new Ext.Net.MessageBoxConfig();
config.Buttons = MessageBox.Button.OK;
config.Icon = icon;
config.Title = Title;
config.Message = Content;
alert.Show(config);
}
private string GetStringCheckedItem(MultiCombo obj)
{
StringBuilder sb = new StringBuilder();
foreach (var item in obj.SelectedItems)
{
sb.Append("''" + item.Value + "'',");
}
if (sb.Length > 0)
sb.Remove(sb.Length - 1, 1);
return sb.ToString();
}
protected void btnExport_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
// 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
HtmlForm form1 = new HtmlForm();
form1.Page = this.Page;
form1.Controls.Clear();
form1.Controls.Add(GridView1);
form1.RenderControl(oHtmlTextWriter);
Response.Output.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
}
}

以上代码没有问题,问题出在数据上ValueField字段中的数据不能含有空格,否则将出现上述不能多选的问题(多选失效)。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值