[英]filtering data view results and binding values to a grid which has paging
我有一個分頁的網格視圖。 將數據綁定到網格視圖后,我將根據下拉列表的選擇對網格進行過濾。 結果是2頁。 但是,當我單擊第二頁時,網格正在刷新原始結果。 這是我的代碼:
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);
}
有人可以幫忙嗎?
這是我的問題的解決方案。 我們需要在分頁時重新過濾結果。 在更改網格頁面時,我們需要更改代碼,如下所示:
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.