Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Help with simple datagrid paging and sorting issue

Reply
Thread Tools

Help with simple datagrid paging and sorting issue

 
 
Charlie Kunkel
Guest
Posts: n/a
 
      04-22-2004
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();
}
 
Reply With Quote
 
 
 
 
Juliet Choy
Guest
Posts: n/a
 
      04-23-2004
Hi Charlie,

This great article from Scott Mitchell had mentioned this problem:
http://msdn.microsoft.com/asp.net/us...lesortable.asp

That you need to set CurrentPageIndex = 0 in your sort handler.
Hope this help.

Regards,
Juliet Choy
Hong Kong
Microsoft MVP - ASP.NET

Charlie Kunkel wrote:

> 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();
> }

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting and paging issue JohnE ASP .Net 6 08-22-2009 12:05 AM
Combining numeric mode paging and nextPreview paging in datagrid Red ASP .Net 1 03-12-2005 11:41 PM
datagrid paging - customising paging style wh1974 ASP .Net 0 01-12-2005 03:48 PM
Programatically add sorting and paging to a datagrid =?Utf-8?B?bWc=?= ASP .Net 1 05-27-2004 01:55 PM
Datagrid custom sorting and paging using stored procedure Mo ASP .Net 1 01-30-2004 07:56 PM



Advertisments