Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
Charlie Kunkel #1
Help with simple datagrid paging and sorting issue
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();
}
Charlie Kunkel Guest
-
What's the easiest way to..user define class...datagrid..paging..sorting..
I have a large number of user define class objects and want display in a datagrid and able to perform paging and column sorting. It seems using... -
Datagrid does not respond to any sorting, dataview filtering, or paging events
This is my third VB.NET forum to try and help me with my problems and several people have failed so I am hoping someone here is a TRUE GURU on... -
Dynamic columns in DataGrid, Paging/Sorting and Data Caching
Hi, I have a DataGrid that has no columns and that is populated with columns based on data obtained from DB during PageLoad in the following way:... -
DataGrid - sorting/paging problem
Hi. I have created a datagrid (datagrid1) without any columns on a aspx page. Then aspx.vb adds columns from a database. It is somthing like... -
How to bring paging, sorting and hyperlinking functioanlities in a datagrid?
Hi there, I just started asp.net code 3 days ago from now. I have a situation in one of my pages that i need to provide all three... -
Juliet Choy #2
Re: Help with simple datagrid paging and sorting issue
Hi Charlie,
This great article from Scott Mitchell had mentioned this problem:
[url]http://msdn.microsoft.com/asp.net/using/building/webcontrols/default.aspx?pull=/library/en-us/dnaspp/html/aspnet-pageablesortable.asp[/url]
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();
> }Juliet Choy Guest



Reply With Quote

