DataGrid Paging Problem
Currently I have a form which prompt to user select multiple display columns for the datagrid, and datagrid will be populated, using Itemplate to generate column dynamically, once user submit their selections. I need to implement paging, and in my case, datagrid's default paging feature is good enough. But here is the problem. According to the book, I just need to specify CurrentPageIndex = e.NewPageIndex with in the PageIndexChanged function, but that doesn't seem to work. If I have the BindData at page load then default paging works correctly, but user needs to specify the criteria first, and that happen before the page performs postback.
following is my code, can anyone give me a hint as to what I missed?
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
private void btn_Click(object sender, System.EventArgs e)
{
BindData();
}
private void BindData()
{
string cmdTxt = "Select num, title, acronym, comment from View";
DataSet ds = SQLHelper.ExecuteDataSet(cmdTxt);
foreach(DataColumn dc in ds.Tables[0].Columns)
{
dg.Columns.Add(DynamicColumns(dc.ColumnName));
}
dg.DataSource = ds.Tables[0];
dg.DataBind();
}
protected TemplateColumn DynamicColumns(string column)
{
TemplateColumn genericcolumn = new TemplateColumn();
genericcolumn.HeaderText = column;
genericcolumn.ItemTemplate = new ItemColumnTemplate(column);
return genericcolumn;
}
private void dg_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
dg.CurrentPageIndex = e.NewPageIndex;
BindData();
}
|