- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在asp.net中创建一个GridView,它可以像Excel一样过滤gridview的每一列。为此,我创建了一个 Gridview,并在 GridView 每一列的标题上使用 Jquery 多选小部件来执行过滤。
<cc1:GridView ID="gvDailyTracker" runat="server" CssClass="mGrid" CellSpacing="2" AutoGenerateColumns="false"
ShowFooter="false" AllowPaging="true" OnPageIndexChanging="gvDailyTracker_PageIndexChanging" OnRowDataBound="gvDailyTracker_RowDataBound"
OnRowCommand="gvDailyTracker_RowCommand" OnRowEditing="gvDailyTracker_RowEditing" OnSelectedIndexChanged="gvDailyTracker_SelectedIndexChanged"
OnDataBound="gvDailyTracker_DataBound">
<EmptyDataRowStyle BackColor="LightBlue" Width="1180" />
<EmptyDataTemplate>
No Data Found From The Current Selection,Please Select Appropriate Search Criteria.
</EmptyDataTemplate>
<Columns>
<asp:TemplateField SortExpression="DateProcessed" HeaderStyle-Font-Bold="true"
HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
<HeaderTemplate>
<select id="ddlDateProcessed" name="test" runat="server" multiple="true" style="width: 100px;">
</select>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblDateProcessed" runat="server" Text='<%#Eval("DateProcessed") %>' CssClass="GridContent" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="InvoiceFileName" HeaderStyle-Font-Bold="true"
HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
<HeaderTemplate>
<select id="ddlInvoiceFilename" name="test" runat="server" multiple="true" style="width: 100px;">
</select>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblInvoiceFileName" runat="server" Text='<%#Eval("InvoiceFileName") %>' CssClass="GridContent" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</cc1:GridView>
<script type="text/javascript">
$(document).ready(function () {
$("#MainContent_gvDailyTracker_ddlDateProcessed").multiselect({
SelectedText: 'DateProcessed',
noneSelectedText: 'DateProcessed',
close: function () {
var dateProcessed = $("#MainContent_gvDailyTracker_ddlDateProcessed").multiselect("getChecked").map(function () {
return this.value;
}).get();
document.getElementById('<%=txtddlDateProcessed.ClientID%>').value = dateProcessed;
document.getElementById('<%=btnPostBack.ClientID %>').click();
},
beforeopen: function () {
$("#MainContent_gvDailyTracker_ddlDateProcessed").multiselect("checkAll");
},
minWidth: 120
});
$("#MainContent_gvDailyTracker_ddlInvoiceFilename").multiselect({
SelectedText: 'InvoiceFileName',
noneSelectedText: 'InvoiceFileName',
close: function () {
var InvoiceFilename = $("#MainContent_gvDailyTracker_ddlInvoiceFilename").multiselect("getChecked").map(function () {
return this.value;
}).get();
document.getElementById('<%=txtddlInvoiceFileName.ClientID%>').value = InvoiceFilename;
document.getElementById('<%=btnPostBack.ClientID %>').click();
},
beforeopen: function () {
$("#MainContent_gvDailyTracker_ddlInvoiceFilename").multiselect("checkAll");
},
minWidth: 120
});
});
function test() {
BindAllMultiSelectData();
var dateProcessed = $("#MainContent_gvDailyTracker_ddlDateProcessed").multiselect("getChecked").map(function () {
return this.value;
}).get();
var InvoiceFilename = $("#MainContent_gvDailyTracker_ddlInvoiceFilename").multiselect("getChecked").map(function () {
return this.value;
}).get();
document.getElementById('<%=txtddlDateProcessed.ClientID%>').value = dateProcessed;
document.getElementById('<%=txtddlInvoiceFileName.ClientID%>').value = InvoiceFilename;
}
function BindAllMultiSelectData() {
$("#MainContent_gvDailyTracker_ddlDateProcessed").multiselect({
SelectedText: 'DateProcessed',
noneSelectedText: 'DateProcessed',
close: function () {
var dateProcessed = $("#MainContent_gvDailyTracker_ddlDateProcessed").multiselect("getChecked").map(function () {
return this.value;
}).get();
document.getElementById('<%=txtddlDateProcessed.ClientID%>').value = dateProcessed;
document.getElementById('<%=btnPostBack.ClientID %>').click();
},
minWidth: 120
});
$("#MainContent_gvDailyTracker_ddlInvoiceFilename").multiselect({
SelectedText: 'InvoiceFileName',
noneSelectedText: 'InvoiceFileName',
close: function () {
var InvoiceFilename = $("#MainContent_gvDailyTracker_ddlInvoiceFilename").multiselect("getChecked").map(function () {
return this.value;
}).get();
document.getElementById('<%=txtddlInvoiceFileName.ClientID%>').value = InvoiceFilename;
document.getElementById('<%=btnPostBack.ClientID %>').click();
},
minWidth: 120
});
</script>
用于过滤 gridView 的 C# 代码
protected void btnPostBack_Click(object sender, EventArgs e)
{
if (!txtddlDateProcessed.Text.Equals(null) && txtddlDateProcessed.Text != string.Empty)
{
string filter=txtddlDateProcessed.Text;
filter = filter.Replace(",", "','");
string strFilter="[DateProcessed]" + " in ('" + filter + "')";
FilterHeader(strFilter);
}
if (!txtddlInvoiceFileName.Text.Equals(null) && txtddlInvoiceFileName.Text != string.Empty)
{
string filter=txtddlInvoiceFileName.Text;
filter = filter.Replace(",", "','");
string strFilter="[InvoiceFileName]" + " in ('" + filter + "')";
FilterHeader(strFilter);
}
ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "test();", true);
}
到目前为止,一切都工作正常,我可以过滤 GridView 。现在我真正想要的是,在过滤 GridView 之后,在多选小部件上所做的选择保持不变。目前,过滤后所有多选都未被选中。
注:-1。我正在动态绑定(bind)多选。(该列值的不同记录绑定(bind)到多选)
private void BindHeaderDropDown(string columnName, DataTable dt, string controlName)
{
System.Web.UI.HtmlControls.HtmlSelect objControlName = (System.Web.UI.HtmlControls.HtmlSelect)gvDailyTracker.HeaderRow.FindControl(controlName);
DataView view=new DataView(dt);
DataTable distinctValues = view.ToTable(true, columnName);
objControlName.DataSource = distinctValues;
objControlName.DataTextField = columnName;
objControlName.DataValueField = columnName;
objControlName.DataBind();
}
在绑定(bind)网格后加载页面时,我通过调用 BindHeaderDropDown
来绑定(bind)多选小部件。函数 使用所选值过滤 GridView 后,我再次调用相同的函数,即 BindHeaderDropDown
用于绑定(bind)多选。如果我在过滤后没有调用此函数,则不会将任何内容绑定(bind)到多选,并且它是空白的,没有单个复选框项目。
请帮助我并指导我,我该怎么办?提前致谢。
最佳答案
更好的是,您可以将多选值保存在隐藏字段中。再次根据隐藏字段值,您可以在多选下拉列表中填充这些项目。
此方法用于将值存储在隐藏字段中
close: function (event, ui) {
var values = new Array();
$("#ddlAssignedTo").multiselect("getChecked").each(function (index, item) {
values.push($(item).val());
});
$("input[id*=hdnAssignTo]").val(values.join(","));
}
这是根据隐藏字段填充多选下拉列表中的值的方法
function loadSelectedUsers() {
$("#ddlAssignedTo").multiselect("uncheckAll");
var listAssigned = $("#ctl00_MainContent_ddlAssignedTo option:selected").length;
if (listAssigned == 0) {
if ($("#<%=hdnAssignTo.ClientID%>").val() != null && $("#<%=hdnAssignTo.ClientID%>").val() != undefined && $("#<%=hdnAssignTo.ClientID%>").val() != "") {
var arrUserIdSelected = $("#<%=hdnAssignTo.ClientID%>").val().split(',');
if (arrUserIdSelected != null && arrUserIdSelected.length > 0) {
for (var iCount = 0; iCount < arrUserIdSelected.length; iCount++) {
$("#ddlAssignedTo").multiselect("widget").find("input:checkbox[value='" + arrUserIdSelected[iCount] + "']").attr("checked", "checked");
$("#ddlAssignedTo option[value='" + arrUserIdSelected[iCount] + "']").attr("selected", 1);
$("#ddlAssignedTo").multiselect("refresh");
}
}
}
}
}
关于c# - 在 Jquery UI 多选小部件中回发后,所选项目仍保持选中状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22066569/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!