Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 25th, 2016, 02:52 PM
Authorized User
 
Join Date: Aug 2015
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.
 
Old July 1st, 2016, 11:32 PM
Friend of Wrox
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

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">
   <ItemTemplate>
     <asp:LinkButton runat="server" Text="Select" CommandName="Select" CausesValidation="False" ID="lnkSelect" CommandArgument='<%# Bind("SAK") %>' />
   </ItemTemplate>
</asp:TemplateField>

Last edited by mmorgan30; July 1st, 2016 at 11:42 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete command in GridView AlexW ASP.NET 4 General Discussion 10 July 17th, 2011 06:56 AM
Copy One Row from Gridview to Gridview lvprasad2007 ASP.NET 2.0 Professional 0 July 28th, 2009 08: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 08:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.