It shows that you are unregistered. Please register with us by clicking Here
![]() |
|
![]() |
![]() | Register - FAQ - Today's Posts - New Posts - Support - Search | ![]() |
![]() |
![]() |
|
LinkBack | Thread Tools | Display Modes | ![]() |
|
|
#1 (permalink) |
|
Junior Member
Join Date: Jul 2006
Age: 45
Posts: 3
|
If you set AllowPaging="true" or AllowSorting="true" on a GridView control without using a DataSourceControl DataSource (i.e. SqlDataSource, ObjectDataSource), you will run into the following errors:
When changing the page on the GridView control: The GridView 'GridViewID' fired event PageIndexChanging which wasn't handled. When clicking a column name to sort the column on the GridView control: The GridView 'GridViewID' fired event Sorting which wasn't handled. As a result of not setting the DataSourceID property of the GridView to a DataSourceControl DataSource, you have to add event handlers for sorting and paging. <asp:GridView ID="gridView" OnPageIndexChanging="gridView_PageIndexChanging" OnSorting="gridView_Sorting" runat="server" /> private string ConvertSortDirectionToSql(SortDirection sortDireciton) { string m_SortDirection = String.Empty; switch (sortDirection) { case SortDirection.Ascending: m_SortDirection = "ASC"; break; case SortDirection.Descending: m_SortDirection = "DESC"; break; } return m_SortDirection } protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { gridView.PageIndex = e.NewPageIndex; gridView.DataBind(); } protected void gridView_Sorting(object sender, GridViewSortEventArgs e) { DataTable m_DataTable = gridView.DataSource as DataTable; if (m_DataTable != null) { DataView m_DataView = new DataView(m_DataTable); m_DataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection); gridView.DataSource = m_DataView; gridView.DataBind(); } } Preston |
|
|
|
|
|
|
|
#2 (permalink) |
|
Banned User
Join Date: Jul 2006
Location: India
Age: 31
Posts: 105
|
Hi,
For Paging you need to set the AllowPaging property of datagrid, and for sorting you need the AllowSorting property of datagrid. You can also set the page style to display the paging in different number of styles like <> or in page number etc. Only setting the allowpaging property will not complete your task for paging. For make it running you need to write a single line of code in the code behind file on the datagrid's PageIndexChanged event. DataGrid1.CurrentPageIndex =e.NewPageIndex this will make it working. Cheers, Amit |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How can I add Caption/Title to GridView? | bradley | .NET | 0 | 07-06-2006 05:30 PM |