Extending GridView ( replacing the default behaviour )

Hi,

I have trouble extending the GridView class to suit my rather specific needs.

My main trouble (besides multiple smaller ones) is that I want to be able to collapse multiple rows inside the table.

Short background:
I have a GridView that has the added functionality of grouping data per column ( Basically sorting the data and adding a header/footer around groups with the same value in that column ), it looks like this:



It works fine and I can collapse entire groups of data, but the problem is that all this is done after the GridView has retrieved its data from the DataSource. All the group headers and collapsing is done after the table of the GridView has been created. Its all "post processing".

This leads to some problems:
- I need to retrieve variable amounts of rows as soon as any group is collapsed ( if a group spanning all of the table is collapsed, the table is suddenly empty, except for the single group header ), to avoid situations like this:



- To know how many extra rows to get for the above problem, I need to know the amount of rows in every group, even if the group starts or ends outside the view of the table.

- I need to intercept the table creation in GridView before it is run and replace or change how it works, but the implementation of GridView hides its data and implementation pretty well, and getting as far as I have has so far already resulted in some ugly code.

So what I really want to do is to start with the exelent control GridView, and more or less replace the rendering of the rows with my own version... This part of the GridView is well hidden and I have problems finding a way to override the standard behaviors Crying [:'(]

I was helped a lot by the simpler tutorials on GridView extending, but I have found no examples of bigger extensions.

Has anyone else extended the GridView in any way that is more complex than changing the color of a row or adding a details row to the table?


There IS a monkey!
-1
gronnbj
11/9/2005 2:35:31 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
524 Views

Similar Articles

[PageSpeed] 12

Well, I have, but since I wrote the GridView control, I might not count. :)

If you're looking to change the way the outer table is rendered, I'm afraid your only option is to override the big CreateChildControls method.  The reason that what you're describing is difficult is that CreateChildControls receives an IEnumerable.  Keep in mind that you might get a DbDataReader, which implements IEnumerable but is a forward-only, read-only cursor.  That means that once you've looked at a data record and gone to the next record, you can't go back.  This is especially difficult when you're implementing grouping, as you are.  Also, keep in mind that the GridView only receives data- it doesn't get much control over what or how much data is requested (besides via the DataSourceSelectArguments).

You can implement the scenario you describe above, but the limitations with IEnumerable and record selection mean that you're going to have to be creative with the existing interfaces or require that your data source implement additional interfaces.  For instance, we require that the data source implements ICollection for paging to work.  If you do something similar, you will have an easier time figuring out your group rows before you create the table.  If you want to control just how or if rows are created, you can easily override CreateRow().  However, without overriding CreateChildControls(), you can't change the format of a row based on data for different data items.

Now, to your specific questions. 
I need to retrieve variable amounts of rows as soon as any group is collapsed ( if a group spanning all of the table is collapsed, the table is suddenly empty, except for the single group header ), to avoid situations like this:
Are you using server-side paging?  If so, then you can just change the parameters by overriding CreateDataSourceSelectArguments and changing the MaximumRows and StartRowIndex members.  If you're not using server-side paging, you should have all the rows of data already present and you can just render more of them.

To know how many extra rows to get for the above problem, I need to know the amount of rows in every group, even if the group starts or ends outside the view of the table.
For this, you will probably have to require an additional interface that you can use to figure out how many records are in each group, or as you read through the data, you'll have to save it off so you can read through it again to render it.  You may end up having to request all the remaining data if you can't get a group row count through an additional interface.

I need to intercept the table creation in GridView before it is run and replace or change how it works, but the implementation of GridView hides its data and implementation pretty well, and getting as far as I have has so far already resulted in some ugly code.
Yes, CreateChildControls is the method you want to override.  It creates the outer table and then enumerates through each data item and calls CreateRow to create each row in the table.

Hope this helps...


Polita Paulus

This posting is provided "AS IS" with no warranties, and confers no rights.
1
phuff
11/11/2005 12:25:06 AM
Hi, and thanx for your very complete answer.
Nice to know who the author of  GridView is, now I can personalize my cries of frustration here at the office Wink [;)]

Anyways: Based on repeated failures, some actual thinking every now and then and your reply, I think I found an acceptable solution to my problem:
As GridView is very good at displaying the data it gets, I decided to give it wat it wants instead of trying to make it do complex intelligence work.
As we will be using a rather specialized object as a data source, I will simply give it the data it needs to generate the exact rows to be displayed in the GridView... Now I can do all I need by only intercepting row creation with "CreateRow" and ask the data if it is header-data or footer-data or just regular data. Not having to add and/or remove lined in the table simplifies things a great deal.

By moving the responsibility to the data source, I suddenly have total control over the code instead of having to create my own versions of your exelent code Smile [:)]

Big thanx for the insights into the dark heart of the GridView.

There IS a monkey!
1
gronnbj
11/14/2005 8:51:27 AM

If you have control over your data source, that is a much simpler way to go.  If you need to use a generic data source, obviously you're back to square one.  Glad this solution will work for you!


Polita Paulus

This posting is provided "AS IS" with no warranties, and confers no rights.
1
phuff
11/14/2005 8:26:17 PM
Reply:

Similar Artilces:

Extending the BoundField class to extend the Web GridView control
Hi, I am writing an extension to the Web GridView control that requires me to hold an additional property (AllowSelect) for each of the bound columns. To do this I have extended the BoundField class. (see code below) I have three questions:1) When I create the GridView, the data bound fields are tagged with <asp:BoundField.... even though the control itself is tagged <cc1:MyGridView... to reference the additional properties, I need to manually edit this to <cc1:BoundField...  ("cc1" is the tag prefix for my registered assembly. ( <%@ Register Assembly=&qu...

Extender control ... cannot extend controls of type ...
Hi all,   I have a custom ImageButton that inherits from the standard ImageButton. When I try to extend this button with ConfirmButtonExtender, I receive the following error:   Extender control 'cbeDelete' cannot extend 'ibDelete'. Extender controls of type 'AjaxControlToolkit.ConfirmButtonExtender' cannot extend controls of type 'MyControls.ImageButton'.   Thx in advance Any suggestions? Even I am having same problem....

gridview control in another gridview control
Hi ia have a questioni have a gridview control which contains button in one colum.now my question is i need another gridview to be placed in the  first gidviewso that when i click on the button the second gridview will populate the data.now my question is how to place second gridview in first gridview.or is there any approach like first grid itself acting as parent and child.please help me  Hi sirikalavalapalli:                I think nested gridview will help you. Check this link and it will show you how...

Help Req: !!! :- On Disabling Controls Present inside a Gridview control
Hi All, We have A requirement Where we have disable controls inside a grid.These controls can be textbox, DropDownlist (in TemplateField), ComandField present inside the grid.We have to call a generic method for doing the same .(since it can be done for multiple grid.) PFB the code snippet we use. Which disables all the controls inside the page.The bolded part of the code is used to loop inside a grid view.(Not Working.)Is this ideal way to deal with the requirement.Or can someone suggest be a better way.        public void DisableMe(Page p1, st...

Gridview control embedded in another gridview control
I am writing an ambulance crew scheduling application on the web and I need some help completing the last part.  I have an access database that has three tables: user table, shift table (describing the shifts available), and a schedule table (that stores shift by shift_id and user by user_id).  I have a gridview control that will display the available shifts but I cannot get the embedded gridview control that will display the user that is signed up for each shift to display because I cannot figure out how to use the OnRowDataBound method.  I need a simple VB example of how to...

Extended GridView Control
I would like to invite you to check my latest article on ASPAlliance under the title of : Extended GridView Control Hope you will enjoy it! RegardsBilal Hadiar, MCP, MCTS, MCPD, MCTMicrosoft MVP - Telerik MVP...

Extending GridView control
Hello I am trying to write my own DataGrid by extending ASP.NET 2 GridView class. I was trying to personalize Pager by overriding InitializePager method, in which I created couple of LinkButtons, subscribing them to Command event. Code to create LinkButtons followsprivate LinkButton PagerLinkButton(string text, string command) {LinkButton lnk = new LinkButton(); lnk.ID = id;lnk.CausesValidation = false; lnk.Text = text;lnk.Style.Add("padding-left", "5px"); lnk.Style.Add("padding-right", "5px");lnk.CommandName = "pager"; lnk.Command...

Extending the GridView control
G'day folks! This is my first post so i apologize if i've placed it in the wrong forum.  I've also searched for related threads but couldn't find anything - please point me in the right direction if this has been discussed previously. I've set myself a little challenge to try and create a customised GridView server control.  I'm just using this exercise to learn a bit about events and the page lifecycle, so creating a full-blown, effective and user-friendly control isn't my main concern here (at least, not immediately).  Essentially, i want to ext...

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: http://forums.asp.net/t/1069245.aspx Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

Master Details in two seperate GridView Controls
I am simply trying to have a list of people in the top grid control (works fine), then when selected have the second Grid Control show details for that person(not working). Here is what I am trying from the load event: Sub BindData() Dim myConnection As New MySql.Data.MySqlClient.MySqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionSql")) Dim strPersonSQL, strActSQL As String strPersonSQL = "select row_id, first_name, last_name, middle_initial, dsi_id, created, created_by, program_of_study, email from tbl_person" Dim myPerCommand As New MySqlClient.MySqlComm...

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

Datagrid(.net 1.1) to GridView(.net 2.0) and using the RowUpdating event how to extract the values from the controls.
Ok  This is the settings: I use a Viewgrid with only itemtemplate colums for example. <asp:TemplateField HeaderText="Test"><ItemTemplate><asp:Label id="LBL_Test" text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' runat="server" meta:resourcekey="LBL_TestResource1"></asp:Label></font></ItemTemplate> <EditItemTemplate><asp:TextBox ID="HDN_Test" Text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' Runat="server" meta:resourcekey="HDN_TestResource1" /></EditItemTemplate></asp:TemplateField>  The ...

There is a Gridview Control in the tmplate field of another GridView Control.
    For instance,a gridview displays the information of the  students in a class.A table is recording the information except their mark.There is another table recording the mark of the students whose foreign key is the primary key of the previous table.   string strSQLconnection=".................."; SqlConnection sqlCononection=new SqlConnection(strSQLconnection); SqlCommand sqlCommand=new SqlCommand("select * from stuendent where classID=1",sqlConnection); SqlConnection.Open(); SqlDataReader reader=sqlCommand.ExecuteReader(); GridVie...

Using the extended hover control to pop up an image in a panel, how do I make the imageurl of the popup image change to that of the control that has extended hover control
I have a list of thumbnails, and one panel with a image in it.  I want to be able to hover over the thumbnails and show the image enlarged in the image of the popup panel change to the imageurl of the thumbnail.  I konw it has to be done in script.  What would it look like. Thanks Hi, Please check the below sample:   <script type="text/javascript"> function getTop(e) { var offset=e.offsetTop; if(e.offsetParent!=null) offset+=getTop(e.offsetParent); return offset; } f...

Web resources about - Extending GridView ( replacing the default behaviour ) - asp.net.presentation-controls

Facebook Extending Custom Audiences To All Advertisers, All Ad Interfaces
Facebook’s custom audiences ad-targeting option, which was initially introduced in October 2012 via the social network’s ads application-programming ...

Extending the Adoption Schedule for Ads API version 2.2
New blog post for extending v 2.2 timeline.

The Platform Rush of ’08: Extending Social Platforms to the Open Web
... of ’07 was about creating APIs for third party developers to build applications on social networks, the Platform Rush of ’08 is about extending ...

Extending Unemployment Benefits Makes Good Economic Sense Too
Our lawmakers will be debating this week the emergency benefits received by the long-term unemployed. There are solid economic and social arguments ...

President Obama Speaks on Extending Tax Cuts for Middle Class Families - YouTube
President Obama calls on Congress to extend the tax cuts for the 98 percent of Americans making less than $250,000 for another year so that millions ...

Amazon aims to take over the world by extending reach
Will internet giant Amazon evolve into the biggest retailer in the world? Katherine Rushton reports.

Bresnan eyes extending wood fire ban
Bresnan eyes extending wood fire ban

Vietnam legacy: Extending the hand of friendship to old enemies
ON Australia Day 1968, a small force of Australian Diggers stormed a Vietnamese camp and found themselves locked in a bloody 17-hour firefight ...

Crown casino in secret talks to seek deal on extending licence until 2092
CROWN Casino is demanding a 99 year licence from the government in a radical bid that would extend its operations until 2092.

BMW Championships: Aussie Jason Day closes in on world No. 1 ranking after extending lead
THE drought lasted nearly two decades, but now Jason Day stands on the precipice of becoming the second Australian world golf No. 1 in 12 months. ...

Resources last updated: 11/21/2015 9:19:15 PM