Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > ASP.NET 4.5 General Discussion
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 4.5 General Discussion For ASP.NET 4.5 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4.5 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old February 25th, 2016, 02:52 PM
Authorized User
Points: 91, Level: 1
Points: 91, Level: 1 Points: 91, Level: 1 Points: 91, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2015
Location: rural Minnesota
Posts: 19
Thanks: 6
Thanked 0 Times in 0 Posts
Default Gridview enablesort and row command

Is there a way to use the enablesorting and enablepaging fuctions with gridview and at the same time use onrowcommand for multiple buttons

or alternately include multiple select buttons and extract the text of the button with onselectedindexchanged to detect different functions.

I have a table with many rows, so paging and sorting would be helpful. At the same time, it would be helpful to have buttons to 'Do this before deleting selected row', 'Do this before editing selected row', or 'go to a new page to show child records of the selected row'.

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old July 2nd, 2016, 12:32 AM
Friend of Wrox
Points: 528, Level: 8
Points: 528, Level: 8 Points: 528, Level: 8 Points: 528, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts

Yes OnRowCommnad is fired for any event that is started in a gridview row. when sorting and paging is enabled I make sure that the button Command arg is bound to the key of the data item. so that I can re-fetch the item from my backing cache or DB for manipulation (if not using some data tracking object such as ObjectDataSource). The edit index and delete index values that are typically in the edit/delete event for example will not always work in instance where sorting and paging are enabled.

When using OnRowCommand for multiple button clicks within a row interrogate the CommandName of the event sender to see what you are getting for the command action. This also means that if you are not using the predefined buttons.you will have to populate the CommandName on your button (Template column definition).

Here is an example of select command button I have used in a project that has an ajax popup window to display the full details of the of the row being selected (the gridview only show the snapshot of the data). I populate the popup window by re-calling the backing data object from cache using the commandArg that is bound to the system assigned key (sak) of the object. All of this is going whilst paging is enable.

HTML Code:
<asp:TemplateField ShowHeader="False" ItemStyle-Width="50px">
     <asp:LinkButton runat="server" Text="Select" CommandName="Select" CausesValidation="False" ID="lnkSelect" CommandArgument='<%# Bind("SAK") %>' />

Last edited by mmorgan30; July 2nd, 2016 at 12:42 AM.
Reply With Quote

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete command in GridView AlexW ASP.NET 4 General Discussion 10 July 17th, 2011 07:56 AM
Copy One Row from Gridview to Gridview lvprasad2007 ASP.NET 2.0 Professional 0 July 28th, 2009 09:29 AM
Gridview with only one row mallikalapati ASP.NET 2.0 Professional 0 February 25th, 2008 06:46 AM
GridView Delete Command jamara ASP.NET 2.0 Professional 0 February 23rd, 2007 02:16 PM
Adding a row without using Update command wpyoung2600 ADO.NET 1 August 22nd, 2004 09:26 AM

All times are GMT -4. The time now is 09:14 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.