Help with simple datagrid paging and sorting issue

C

Charlie Kunkel

Please help!

I have a simple web app that displays some search fields, posts back
to itself onclick of the search button, and shows the results in a
datagrid. I have default paging turned on, and SortExpressions set for
all the datagrid columns. Yet, any time OnPageIndexChanged or
OnSortCommand execute, i get either an empty datagrid, or the
ever-annoying "Invalid CurrentPageIndex value. It must be >= 0 and <
the PageCount." error. I can't figure out WHY!

Here's the relevant code:


using ...

private void Page_Load(object sender, System.EventArgs e)
{
sqlConnection.Open();
if (!Page.IsPostBack)
{
//populate dropdowns
}

}

private void btnSearch_Click(object sender, System.EventArgs e)
{

#region "Set Command Object Parameters equal to current form
values"
sqlDataAdapter1.SelectCommand.Parameters[1].Value =
txtRoadName.Text.ToString();//RoadName
...
#endregion

sqlDataAdapter1.Fill(dataSet11);
DataGrid1.CurrentPageIndex = 0;
BindData();
}

protected void BindData()
{
//dataSet11.Clear();
//dataSet11.AcceptChanges();
DataGrid1.DataSource = dataSet11.Tables[0].DefaultView;
DataGrid1.DataBind();
sqlConnection.Close();
}

protected void Sort (object sender, DataGridSortCommandEventArgs e)
{
//sort the rows in the DataView in the specifiec order
dataSet11.Tables[0].DefaultView.Sort = e.SortExpression + " ASC";
BindData();
}


protected void ChangeGridPage(object sender,
DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindData();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top