分页问题 [英] Paging issue
本文介绍了分页问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在动态绑定gridview,当我尝试分页时,我什至无法看到页面上的分页.我的编码如下.请
建议我错过了什么.我在Page_Init事件中绑定Gridview.paging根本不显示gridview.这可能是原因.我也在使用pageindexchanging事件,但仍然不能
来查看页面上的分页.我一直都绑定.我需要动态创建Gridview,因此我在后面编写代码
Hi All,
I am binding gridview dynamically and when i try for paging I am not able to even see the paging on the page.My coding is as below.Please
suggest what I am misssing.I am binding Gridview in Page_Init event.paging is not showing at all with gridview.what could be the reason.I am using pageindexchanging event also but still I am not able
to see paging on the page.I am binding all times.I need the Gridview to be created dynamically so I am writing code behind
workGrid.RowEditing += new GridViewEditEventHandler(workGrid_RowEditing);
workGrid.RowDeleting += new GridViewDeleteEventHandler(workGrid_RowDeleting);
workGrid.RowDataBound += new GridViewRowEventHandler(workGrid_RowDataBound);
TemplateField BtnTmpField = new TemplateField(); BtnTmpField.ItemTemplate = new GridViewTemplate(ListItemType.Item, "Modify", "Command");
BtnTmpField.HeaderTemplate = new GridViewTemplate(ListItemType.Header, "Modify", "Command"); BtnTmpField.EditItemTemplate = new GridViewTemplate(ListItemType.EditItem, "...", "Command"); workGrid.Columns.Clear();
workGrid.Columns.Add(BtnTmpField);
for (int workCnt = 0; workCnt < dtWorksGrid.Columns.Count; workCnt++)
{ TemplateField ItemTmpField = new TemplateField();
// create HeaderTemplate
ItemTmpField.HeaderTemplate = new GridViewTemplate(ListItemType.Header, dtWorksGrid.Columns[workCnt].ColumnName, dtWorksGrid.Columns[workCnt].DataType.Name);
ItemTmpField.HeaderStyle.Width = Unit.Pixel(145);
// create ItemTemplate
ItemTmpField.ItemTemplate = new GridViewTemplate(ListItemType.Item, dtWorksGrid.Columns[workCnt].ColumnName, dtWorksGrid.Columns[workCnt].DataType.Name);
//create EditItemTemplate
ItemTmpField.EditItemTemplate = new GridViewTemplate(ListItemType.EditItem, dtWorksGrid.Columns[workCnt].ColumnName, dtWorksGrid.Columns[workCnt].DataType.Name);
// then add to the GridView
workGrid.Columns.Add(ItemTmpField);
}
workGrid.DataSource = dtWorksGrid;
workGrid.DataBind();
workGrid.AllowPaging = true;
workGrid.PageSize = 5;
workGrid.PageIndexChanging += new GridViewPageEventHandler(workGrid_PageIndexChanging);
void workGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
bindWorkGrid(workType);
reg_workgrid.PageIndex = e.NewPageIndex;
reg_workgrid.DataBind();
}
推荐答案
您是每次绑定还是在使用代码来确保它不会在回发时绑定?为什么要在代码中而不是在模板中设置所有这些内容?
无论如何,Page_Init是错误的数据绑定位置,而prerender是最佳的绑定位置.
Are you binding every time, or are you using code to make sure it does not bind on postback ? Why are you setting all this in code instead of in the template ?
Page_Init is the wrong place to databind anyhow, prerender is the best place to do it.
这篇关于分页问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文