HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource - preCharge Forums
It shows that you are unregistered. Please register with us by clicking Here
preCharge Forums


Nav Green LeftNav Right
preCharge Forums > Website Design & Development > Programming > .NET » HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource


Reply
Tcat Right
 
LinkBack Thread Tools Display Modes Tcat Right
Old 07-06-2006   #1 (permalink)
preston
Junior Member
 
Join Date: Jul 2006
Age: 45
Posts: 3
Default HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

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
preston is offline   Reply With Quote


Old 07-08-2006   #2 (permalink)
agaba175
Banned User
 
Join Date: Jul 2006
Location: India
Age: 31
Posts: 105
Default Sorting and Paging in DATAGRID

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
agaba175 is offline   Reply With Quote

Old 04-01-2009   #3 (permalink)
RaiulBaztepo
Junior Member
 
Join Date: Mar 2009
Posts: 1
Default Very nice resource

Hello!
Very Interesting post! Thank you for such interesting resource!
PS: Sorry for my bad english, I'v just started to learn this language ;)
See you!
Your, Raiul Baztepo
RaiulBaztepo is offline   Reply With Quote

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

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


footer left
All times are GMT. The time now is 10:57 AM.

DISCLAIMER: preCharge Risk Management is not responsible for any opinions, advice or comments expressed on the preCharge Community Forums.
preCharge® is a registered trademark of preCharge Risk Management | chargeback protection | Merchant Account Blog

Powered by vBulletin
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0 RC6

MySpace Layouts | Business Gifts | Business Gifts | Watch Anime Online | Adult ADHD

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49