[英]filtering data view results and binding values to a grid which has paging
I have a grid view which has paging. 我有一个分页的网格视图。 After binding the data to the grid view I am filtering the grid based on selection of dropdown. 将数据绑定到网格视图后,我将根据下拉列表的选择对网格进行过滤。 which is resulting the results in 2 pages. 结果是2页。 But when I clicked on 2nd page the grid is refreshing with original results. 但是,当我单击第二页时,网格正在刷新原始结果。 Here is my code: 这是我的代码:
DataTable dtSyncQueueTransfer = syncStatusBizManager.GetSyncTransferResult(syncRequestId, serverIds, statusIds, txtFileName.Value);
ViewState["SyncResults"] = dtSyncQueueTransfer;
gvSyncQueueList.DataSource = dtSyncQueueTransfer;
gvSyncQueueList.DataBind();
protected void ddlProjectId_SelectedIndexChanged(object sender, EventArgs e)
{
DataTable dtSyncResults = (DataTable)ViewState["SyncResults"];
//To display all the sync results when the dropdown selected value is All.
if (ddlProjectId.SelectedValue.ToString().Equals("All"))
{
gvSyncQueueList.DataSource = dtSyncResults;
gvSyncQueueList.DataBind();
}
//To display the sync results when the user selects a projectId from the drop down.
else
{
DataView viewResults = new DataView(dtSyncResults);
//Filtering sync results based on projectid.
viewResults.RowFilter = "ProjectId =" + Convert.ToInt32(ddlProjectId.SelectedValue);
gvSyncQueueList.DataSource = viewResults;
gvSyncQueueList.DataBind();
}
}
protected void gvSyncQueueList_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvSyncQueueList.PageIndex = e.NewPageIndex;
gvSyncQueueList.DataSource = (DataTable)ViewState["SyncResults"];
gvSyncQueueList.DataBind();
string activetab = GetActiveTab();
ShowTabs(activetab);
}
Can anyone help on this? 有人可以帮忙吗?
Here is the solution for my question. 这是我的问题的解决方案。 we need to re-filter the results on paging. 我们需要在分页时重新过滤结果。 On change of grid page we need to change the code as follows: 在更改网格页面时,我们需要更改代码,如下所示:
protected void gvSyncQueueList_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvSyncQueueList.PageIndex = e.NewPageIndex;
//To view all the sync results when the page first time loads or when the drop down value is all.
if (ddlProjectId.SelectedValue.ToString().Equals("All") || string.IsNullOrEmpty(ddlProjectId.SelectedValue.ToString()))
gvSyncQueueList.DataSource = (DataTable)ViewState["SyncResults"];
//To bind the project results according to drop down value selected in paging.
else
{
DataView viewResults = new DataView((DataTable)ViewState["SyncResults"]);
viewResults.RowFilter = "ProjectId =" + Convert.ToInt32(ddlProjectId.SelectedValue);
gvSyncQueueList.DataSource = viewResults;
}
gvSyncQueueList.DataBind();
string activetab = GetActiveTab();
ShowTabs(activetab);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.