Building a grouping Grid with GridView and ASP.NET AJAX toolkit CollapsiblePanel

by mosessaur| 24 February 2008| 78 Comments

UPDATE: I've posted an update to this post to apply on demand loading of Details data using ASP.NET AJAX PageMethods. I'm demonstrating the usage if CollapsiblePanelExtender client events on the new post. Check it out.

I admit, Matt Berseth is really inspiring me! Few days ago I pass through 2 of his great posts:

The first one is pure design tips one which I used for making good presentation of my demo here. The 2nd post is actually the idea.

Here I'll do the same idea Matt presented in his post, but I'll user ASP.NET 2.0 simple stuff plus ASP.NET AJAX Toolkit CollapsiblePanel control.It is required that you have ASP.NET AJAX Extensions installed to be able to run the sample code.

I'll not go through the presentation tips mentioned in Matt's post, I'll just show my technique to implement grouping idea with GridViews and CollapsiblePanel along with SqlDataSource which of course can be replaced with ObjectDataSource. I should mention that I'm using same style sheets provided in Matt's sample code along with images [View Demo].

Bellow is a screenshot of a running sample:
Collapsible Panel

The whole group is wrapped inside a ComponentArt like design:

   1: <div id="dlg" class="dialog" style="width: 700px">
   2:     <div class="header" style="cursor: default">
   3:         <div class="outer">
   4:             <div class="inner">
   5:                 <div class="content">
   6:                     <h2>
   7:                         Northwind: Orders By Customer</h2>
   8:                 </div>
   9:             </div>
  10:         </div>
  11:     </div>
  12:     <div class="body">
  13:         <div class="outer">
  14:             <div class="inner">
  15:                 <div class="content">
  16:                     <!-- My Code Goes Here -->
  17:                 </div>
  18:             </div>
  19:         </div>
  20:     </div>
  21:     <div class="footer">
  22:         <div class="outer">
  23:             <div class="inner">
  24:                 <div class="content">
  25:                 </div>
  26:             </div>
  27:         </div>
  28:     </div>
  29: </div>

The grouping will display orders by customer from Northwind database. Bellow is the SqlDataSource code for selecting Customers "sqlDsCustomers":

   1: <asp:SqlDataSource ID="sqlDsCustomers" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind %>"
   2:     SelectCommand="SELECT [Customers].[CustomerID], [Customers].[CompanyName], COUNT([OrderID]) TotalOrders
   3:                     FROM [Customers] INNER JOIN [Orders] ON [Customers].[CustomerID]=[Orders].[CustomerID]
   4:                     Group By [Customers].[CustomerID], [Customers].[CompanyName]">
   5: </asp:SqlDataSource>

Now simply I can display my master data (grouping) which will display CustomerID with total number of orders he made:

   1: <asp:Panel CssClass="grid" ID="pnlCust" runat="server">
   2:     <asp:UpdatePanel ID="pnlUpdate" runat="server">
   3:         <ContentTemplate>
   4:             <asp:GridView Width="100%" AllowPaging="True" ID="gvCustomers" AutoGenerateColumns="False"
   5:                 DataSourceID="sqlDsCustomers" runat="server" ShowHeader="False" OnRowCreated="gvCustomers_RowCreated">
   6:                 <Columns>
   7:                     <asp:TemplateField>
   8:                         <ItemTemplate>
   9:                             <asp:Panel CssClass="group" ID="pnlCustomer" runat="server">
  10:                                 <asp:Image ID="imgCollapsible" CssClass="first" ImageUrl="~/Assets/img/plus.png"
  11:                                     Style="margin-right: 5px;" runat="server" />
  12:                                 <span class="header"> <%#Eval("CustomerID")%>: <%#Eval("CompanyName")%>(<%#Eval("TotalOrders")%>Orders)</span>
  13:                             </asp:Panel> <!-- Nested GridView And CollapsibalePanel will placed bellow this line -->
  14:                         </ItemTemplate>
  15:                     </asp:TemplateField>
  16:                 </Columns>
  17:             </asp:GridView>
  18:         </ContentTemplate>
  19:     </asp:UpdatePanel>
  20: </asp:Panel>

This will simply display something like this:
CollapsiblePanelDemo2

Note that the GridView is wrapped inside an ASP.NET Panel control. This is actually important when we start to work with CollapsiblePanel extender.

As we want to implement the grouped data of orders. We will add a nested GridView with its own SqlDataSource. Bellow is a the SqlDataSource for the nested GridView that will display customer orders "sqlDsOrders":

   1: <asp:SqlDataSource ID="sqlDsOrders" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind %>"
   2:     SelectCommand="SELECT [OrderID], [OrderDate], [RequiredDate], [Freight], [ShippedDate] FROM [Orders] WHERE ([CustomerID] = @CustomerID)">
   3:     <SelectParameters>
   4:         <asp:Parameter Name="CustomerID" Type="String" DefaultValue="" />
   5:     </SelectParameters>
   6: </asp:SqlDataSource>
This SqlDataSource is placed inside the ItemTemplate of the master GridView. It is important to note that this SqlDataSource accepts a CustomerID as parameter. To provide this parameter value, we should handle RowCreated Event of the master GridView:
   1: protected void gvCustomers_RowCreated(object sender, GridViewRowEventArgs e)
   2: {
   3:     if (e.Row.RowType == DataControlRowType.DataRow)
   4:     {
   5:         SqlDataSource ctrl = e.Row.FindControl("sqlDsOrders") as SqlDataSource;
   6:         if (ctrl != null && e.Row.DataItem != null)
   7:         {
   8:             ctrl.SelectParameters["CustomerID"].DefaultValue = 
   9:                                ((DataRowView)e.Row.DataItem)["CustomerID"].ToString();
  10:         }
  11:     }
  12: }
Now time to place child nested GridView which will be attached to the "sqlDsOrders". Of course as a nested GridView it will be place just inside the ItemTemplate of the master GridView TemplateField:
   1: <asp:Panel Style="margin-left: 20px; margin-right: 20px" ID="pnlOrders" runat="server">
   2:     <asp:GridView AutoGenerateColumns="false" CssClass="grid" ID="gvOrders" DataSourceID="sqlDsOrders"
   3:         runat="server" ShowHeader="true" EnableViewState="false">
   4:         <RowStyle CssClass="row" />
   5:         <AlternatingRowStyle CssClass="altrow" />
   6:         <Columns>
   7:             <asp:TemplateField ItemStyle-CssClass="rownum">
   8:                 <ItemTemplate><%Container.DataItemIndex + 1%></ItemTemplate>
   9:             </asp:TemplateField>
  10:             <asp:BoundField HeaderText="Order ID" DataField="OrderID" ItemStyle-Width="80px" />
  11:             <asp:BoundField HeaderText="Date Ordered" DataField="OrderDate" DataFormatString="{0:MM/dd/yyyy}"
  12:                 ItemStyle-Width="100px" />
  13:             <asp:BoundField HeaderText="Date Required" DataField="RequiredDate" DataFormatString="{0:MM/dd/yyyy}"
  14:                 ItemStyle-Width="110px" />
  15:             <asp:BoundField HeaderText="Freight" DataField="Freight" DataFormatString="{0:c}"
  16:                 ItemStyle-Width="50px" ItemStyle-HorizontalAlign="Right" />
  17:             <asp:BoundField HeaderText="Date Shipped" DataField="ShippedDate" DataFormatString="{0:MM/dd/yyyy}"
  18:                 ItemStyle-Width="100px" />
  19:         </Columns>
  20:     </asp:GridView>
  21: </asp:Panel>
As you might noticed, this GridView is also wrapped in an ASP.NET Panel control. Now it is time to work with CollapsiblePanel.Just beneath the orders panel I'll place the CollapsiblePanel:
   1: <ajaxToolkit:CollapsiblePanelExtender ID="cpe" runat="Server" 
   2: TargetControlID="pnlOrders"
   3: ExpandControlID="pnlCustomer" CollapseControlID="pnlCustomer"
   4: CollapsedSize="0" Collapsed="True"
   5: AutoCollapse="False" AutoExpand="False" ScrollContents="false" 
   6: ImageControlID="imgCollapsible"
   7: ExpandedImage="~/Assets/img/minus.png" CollapsedImage="~/Assets/img/plus.png"
   8: ExpandDirection="Vertical" />

Now I'll explain the most important properties of the CollapsiblePanel that is used:

  • TargetControlID: Would be the ID of the ASP.NET Panel that contains the contents to be shown or hide. In our case would be the Orders list Panel "pnlOrders"
  • ExpandControlID and CollapseControlID: The ID of the ASP.NET Panel control that will control the expand (show) and collapse (hide) of the contents available in the TargetControlID. In our case would be the customer panel "pnlCust"
  • ImageControlID: The ID of an Image control where an icon indicating the collapsed status of the panel will be placed. The extender will replace the source of this Image with the CollapsedImage and ExpandedImage urls as appropriate. If the ExpandedText or CollapsedText properties are set, they are used as the alternate text for the image
  • ExpandedImage:The path to an image used by ImageControlID when the panel is collapsed
  • CollapsedImage:The path to an image used by ImageControlID when the panel is expanded.

Now when this run, it will display a collapsed list of customers. when you click on the customer it will expand and show list of orders made by that customer.

You can refer to the posted mentioned above for more design and presentation tips. Also the code of this sample is available to download.

Download sample code (291.25 kb) -AjaxControlToolkit v1.0.10920.0 included-

kick it on DotNetKicks.com

Comments (78) -

Josh Stodola
Josh Stodola United States on 1/31/2008 7:36 AM I stumbled upon this blog today, and I remember you from the ASP.NET forums.  Subscribed!
mosessaur
mosessaur Egypt on 1/31/2008 5:53 PM Thank you Josh, of course I do know you well too. And was keeping visiting your blog and amazed with your own blog engine too. Thanks for the visit
Ustes G
Ustes G United States on 2/5/2008 8:49 PM I have tried to implement this same concept about 1 month ago, the problem I had was that my data was huge (100k rows), do you see any performance issues?  
mosessaur
mosessaur Egypt on 2/6/2008 7:04 AM Yes. But only if you are displaying too much data at the same page of the gird. That would cause a performance issue on the client browser, and in fact, during Callbacks of update panel if you use one.
But it depends on the browser, you’ll notice that Opera is performance a bit faster I guess
Ustes G
Ustes G United States on 2/7/2008 1:15 PM So how would you implement the nested grid scenario for large sets of data,that you can't page with a stored proc...?  I am facing this situation now and just want to see how somebody else would go about it.
mosessaur
mosessaur Egypt on 2/8/2008 5:25 AM Well, Myself I do paging through stored procedure, and if the procedure doesn't support paging, I redevelop it to make it support paging. So my Grid Page should display max of 15 rows. and in most cases I do not make paging in the sub one; not too much rows already, however if they contain too much rows, I'll do paging on them too.
But what do you mean you cannot page using stored procedure?!!
Anyway Check out this link:
www.c-sharpcorner.com/.../custompaging.aspx
Rob
Rob United Kingdom on 2/16/2008 7:53 AM I've been trying to replicate what you've done, but even though the code I'm using is very close to yours only the first of the collapsible panel's is working. Did you come across this when you were trying yours?
mosessaur
mosessaur Egypt on 2/16/2008 8:02 AM No, I didn't face such case while building this sample!
Why don't you check your CollapsiblePanel settings?
Or post your code somewhere so I can look at it, because if your code is similar to mine it should work.
Rob
Rob United Kingdom on 2/17/2008 8:36 AM I've already posted the code to here: http://forums.asp.net/t/1232627.aspx
I'm hoping it's one of those things where I've just missed the obvious. Maybe I'll spot it with a fresh head this morning.

Thanks for your help.
mosessaur
mosessaur Egypt on 2/18/2008 4:55 AM I see no issue in your code, but I'd like to ask something, do you notice that the image (collapsible image) change when you click on each group header?!

Because I guess it is data issue, I mean only first recode has details data that is rendered! Where is your data sources in the code?!
jaydev
jaydev United States on 3/21/2008 2:30 PM Hi,
  Again on performance!! Is there any way to populate the child data (I mean Order data) on the expand time (on the click of + sign), rather than initial load itself? It will increase the performance right?? Any suggestion or guidelines to achieve this will be appreciated
mosessaur
mosessaur Egypt on 3/22/2008 10:01 AM Yes Jaydev, that is possible! but it might needs few adjustments, and build another better solution. I guess I'll try to apply that soon
soohyung
soohyung United States on 4/2/2008 12:08 PM Quick question for you.  I am trying to set Pagesize of gridview to 20 instead of 10.  I thought the panel automatically change there size, but it doesn't. Because I am not good at dealing with css, can you please tell me which part do I have to change for displaying 20 records per page. thanks.
mosessaur
mosessaur Egypt on 4/4/2008 10:38 AM Sorry for my late response,
Which panel do you mean exactly?! and I've changed the size to 20 and the page still looks fine!!
The nested panel will not be affected by page size
Rino
Rino on 4/12/2008 2:33 PM Hi,
very good...
But, i added a button for submit varius information.
When the page is reloaded, the CollapsiblePanel does not work.
Do you help me?

Thk.
Rino
mosessaur
mosessaur Egypt on 4/13/2008 12:04 AM Hey Rino,
Could you submit your code to me!
Rino
Rino on 4/13/2008 12:38 AM I sent you an email.
Thanks.

Rino
Jayashree Chakraborty
Jayashree Chakraborty India on 4/29/2008 11:29 AM Is it possible for u to give me the source code of CollapsiblePanel  in Zip format.
Thanks
Jayashree
mosessaur
mosessaur Egypt on 4/30/2008 2:52 PM Hey Jayashree, here is the link to download in ZIP format
mosesofegypt.net/file.axd
Luis
Luis Peru on 6/5/2008 4:15 PM Hi!I found this article very useful! I thought this can't be done in asp 2.0 but u saved my day.
Did you build another solution that populates data on the expand time?
Thanks n grats!
Hans Sissing
Hans Sissing Netherlands on 6/6/2008 8:32 PM Hi Muhammad,

I Implemented a master details view using the ListView (framework 3.5), where edititng the detail is key.
I ran into your blog and with a little tweak is works fine!
Unlike what Dino Esposito demos on msdn (see msdn.microsoft.com/en-us/magazine/cc500643.aspx), with this technique i'm fully capable of implementing updating and inserting too! (He binds the datasource for the default view dynamically).
Great job!

Thanks,

- Hans Sissing.
mosessaur
mosessaur Egypt on 6/8/2008 12:37 AM @luis: Thank you Luis, Actually I didn't yet try to make on demand loading using ASP.NE AJAX Control Toolkit CollapsiblePanel. But I have a plan to try it, but not sure if it will work or not.
I recommend that you checkout my other post mosesofegypt.net/.../...own-Using-jQuery-AJAX.aspx
It contain the feature you wish to implement, but using jQuery not AJAXControlToolKit.
mosessaur
mosessaur Egypt on 6/8/2008 12:39 AM Hans, Thank you Hans, and I wish if you could send me your code, I would like to see what you have done! Because I think I might run into similar case and I don't wish to do from beginning Smile .
Good luck and thank you once again.
Ryan Jose
Ryan Jose Republic of the Philippines on 6/21/2008 6:53 PM hello! the grouping grid is very impressive.. i just want to ask if it is possible that i can make computations between different columns and gridviews? ex.
- MajorCategory: Masonry (Php 9500)(4 materials)
        MaterialName  Quantity   Unit  MaterialUnitPrice   LaborCost    UnitCost  TotalAmount
      -    Cement         2       cc       Php 100          Php 50       Php 150    Php 300
      -    Wires          2      mtrs.     Php 50           Php 20       Php 70     Php 140
      -    Metal         20      pcs.      Php 80           Php 120      Php 200    Php 4000
      -    Hose          10      pcs.      Php 90           Php 20       Php 110    Php 1100

Note: MaterialUnitPrice + LaborCost = UnitCost
      UnitCost x Quantity = TotalAmount
        
mosessaur
mosessaur Egypt on 6/22/2008 7:31 AM @Rayan I think you can! but it might need some work. And you can use LINQ for that. You should prepare your data before displaying them. So I think this is related to behind code not to presentation ASPX code.
Ryan Jose
Ryan Jose Republic of the Philippines on 6/23/2008 7:13 AM oh i see..thanks moses! Smile
Silas
Silas Australia on 6/24/2008 1:39 PM Hi Mohammed, just wanted to say thanks for an excellent article - easy to understand and use - cheers, Silas
mosessaur
mosessaur Egypt on 6/24/2008 2:17 PM Hey Silas, thank you for the cheering comment, and letting me know that the post was good one.
Aaron Prohaska
Aaron Prohaska United States on 6/29/2008 9:52 AM I'm trying to use this with a GridView which is editable and keep getting this error "name cannot be of zero length". How anyone else trying making the parent and child grid editable?
Saied
Saied United States on 7/12/2008 11:00 AM Great post Muhammad.  I have most of it working, but I am running into a few problem.  Paging on the master grid seems to take a while, sometimes too long for me to wait.  I added a PageIndexChanging event to the details grid and when I click to go to a page, it collapses the details and takes me back to the master grid.  This is the code I have for PageIndexChanging ( I am persisting the dataset in a Session object so I don't have to reload it again).

protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
     gvList.PageIndex = e.NewPageIndex;
     DataSet ds = (DataSet)Session["dsResults"];
     gvList.DataSource = ds;
     gvList.DataBind();
}
mosessaur
mosessaur Egypt on 7/12/2008 11:45 AM @Saied Yes this is normal actually because the page will post back and refreshing the page, which will reset the paging on the master grid.
I think the best way to do this is to use AJAX for paging in the second grid.
Saied
Saied United States on 7/12/2008 12:59 PM How can I implement the AJAX Paging Pattern?
Saied
Saied United States on 7/12/2008 3:30 PM The paging on the main grid seems to be taking a while.  I implemented the PageIndexChanging method and stored the dataset returned in a Session, but it still seems to take a while.

Any Ideas??
Mansoor
Mansoor United Kingdom on 7/19/2008 7:39 AM Its Great!
Please Tell me how can i write Events for the nested Gridview. I am using Asp.net(vb) where i dont find the Events for Child Gridview (there are events for the Parent Gridview Only). I want to do this:

Protected Sub ChildGridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim vOnHold As Boolean = Convert.ToBoolean(DataBinder.Eval(e.Row.DataItem, "OnHold"))
            If vOnHold = True Then e.Row.BackColor = Drawing.Color.Red
            End If
        End If
    End Sub
mosessaur
mosessaur Egypt on 7/19/2008 7:43 AM @MansoorWell simply on the GridView Markup add your event handler attachement.
<gridview id="gvChild"  OnRowDataBound="gvChild_RowDataBound" .... >
....
</gridview>
Ziyad
Ziyad United States on 7/20/2008 10:40 AM Now the data grouping in gridview is made simple than ever before...

Try this free grouping gridview control with zero coding effort !

znetcontrols.blogspot.com/.../...pnet-20-with.html

HTH
mosessaur
mosessaur Egypt on 7/20/2008 11:43 AM @jaydev I started to write another post to demonstrate and explain how to do on demand loading when expanding. Should be online in couple of days
Mansoor
Mansoor United Kingdom on 7/21/2008 5:47 PM Thanks a lot.
God Bless You.
mosessaur
mosessaur Egypt on 7/22/2008 2:12 PM I just posted another sample of this applying on demand loading upon expand of the Group Header.
check it out @ mosesofegypt.net/.../...adingUsingPageMethods.aspx
pboy
pboy United States on 7/29/2008 12:15 AM Does Paging work in this sample? I have object datasource bound to main grid. It looks like I need to implment PageIndexChanged method?
mosessaur
mosessaur Egypt on 7/29/2008 3:49 AM I'm using SqlDataSource, to use ObjectDataSource there are some extra work to do though. Checkout ASP.NET Forums or this article
www.c-sharpcorner.com/.../custompaging.aspx
Configuring ObjectDataSource section
biggolo
biggolo Thailand on 9/26/2008 12:02 AM Good Job [thai]ขอบคุณครับ[/thai]
abdulla
abdulla United States on 10/17/2008 6:16 AM very nice document...

how can i open the costomer details in a new window while clicking on a perticular customer or mouser over through a perticular column ?
Youcef Laidi
Youcef Laidi Algeria on 10/21/2008 2:06 AM Hello..You have a very fine Blog.. i have a question for you.. In you projects you have very nice GridView.. can i ask you how you do it ?
Prasanna Padkil
Prasanna Padkil India on 10/22/2008 2:12 AM Nice article. But I have a different issue. I am using Master/Detail implementation. But after page index is changed ie when we go on page 2 it is not expanding the + sign and is not showing the child details. Can someone among you who have faced a similar problem help me.
mosessaur
mosessaur Egypt on 10/22/2008 3:27 AM @Youcef Laidi Thank you for your kind words. In all posts I mentioned that all Grid Designs is taken from http://mattberseth.com
He made very cool GUI for Grids and ListViews and many other things with amazing walkthrough. You can visit his blog and check them out.
Prasanna Padkil
Prasanna Padkil India on 10/22/2008 3:36 AM Hi Youcef,

In the row_created event I have added Id's of each master grid rows. and then added the Id along with the path of details view.
Youcef Laidi
Youcef Laidi Algeria on 10/22/2008 8:24 AM mosessaur..Thank you for your reply fast..
Prasanna Padkil .. Can you please give me a model ..
Ravi
Ravi United States on 10/22/2008 10:33 AM mosessaur,

I am trying to implement nested gridview. My requirement is parent grid and child grid are going to have same columns. So i don't want to display columns for chaild grid, but i want to align chaild gridview columns with parent gridview columns. How can i do this. Can you please tell me.

Thanks
Ravi
mosessaur
mosessaur Egypt on 10/23/2008 11:26 AM @Ravi This can be done using ListView and some CSS work. Exactly how to do it will require to do some coding to make and test to align columns properly. I recommend that you try to do it yourself and checkout post made by Matt that using ListView mattberseth.com/.../...g_a_grouping_grid_with.html
as well as post made by Bill Beckelman beckelman.net/.../...iew-Expansion-Via-jQuery.aspx
Dnyanesh
Dnyanesh India on 10/25/2008 6:27 PM Cool article
Kiran
Kiran India on 10/26/2008 4:55 AM Thnak u Very much,it will helpped me a lot in my project,really i am search this thing since 2 months,at the end i got what i need,rellay great thinking,with simple controls its working,great idea
Iresh
Iresh Qatar on 10/30/2008 12:38 PM @Muhammad

Great and cool. what i was looking for.
but how to implement multigrouping. i mean

group 1
  group 2
      data

I tried but did not getting. will u help me.
mosessaur
mosessaur Egypt on 10/30/2008 1:39 PM @Iresh I really want to implement that as many asked about it!
I just need time as I don't have Immediate solution at the moment. Maybe it is as simple as this one
Iresh
Iresh Qatar on 10/30/2008 2:38 PM @mosessaur
my first group location
second  carat
last displaying data.

now i can get carat value
but not location value.
    
  if (e.Row.RowType == DataControlRowType.DataRow)
        {
          * Will u tell me how to get first group (location) value here.

        }

Rest of all i will do
iresh
iresh Qatar on 10/31/2008 5:26 AM @mosessaur

i did it ,it is working all the way.
only problem getting after expanding subgroup it is not collapsing if clicking on parent group.  and looking also wired. but i dono detail of
collapsibleextender. i just worked around ur example.
let me check detail collapsibleextender
iresh
iresh Qatar on 10/31/2008 5:29 AM means not collapsing subgroup directly. i have to collapse subgroup and then parent group.
iresh
iresh Qatar on 10/31/2008 10:52 PM i did it. its working.
mosessaur
mosessaur Egypt on 11/1/2008 5:35 AM @iresh thank you for sharing your experience but why don't you share how did you make it working with us?! do you have any blog?! if not you can send me sample code and I can blog about this sample when I got sometime.
Kiran
Kiran India on 11/10/2008 8:55 AM I tried with one more internal Expand and collapse pannel but its not working fine,will u help me out in this pls
anup
anup India on 11/17/2008 1:26 AM good job.. i think this is one of the good post i ve ever seen..
Txomin
Txomin Ireland on 11/18/2008 7:16 PM Hi Mosessaur,

First of all a big thank you, I've been trying to do something like that with a grid for a while and your blog has helped me so much.

I've got an issue with the grid tho! I want the user to be able to select the orders so that more information about them can appear in a formview or detailsview. I've added a command field to select the orders. Just to try it , I wanna make it change the background color of the selected row. But when I click on the Select command, all the customers collapse and their orders dissapear (-), and the selected rows backcolor doesn't change. I don't get any error message,and if I page to the next page and go back to the previous one, the customers are populated with their orders...

Could you give me a hand with the problem?  
Tejas
Tejas India on 11/23/2008 5:41 PM Gr8 artical buddy ....

Please help if you can ....
I am facing some problem with Sorting ....
In your code .... I have enabled the GridView's AllowSorting property .... But some how its not allowing me to sort on the fly.
Susan
Susan United States on 11/27/2008 12:37 AM Maybe I'm the only idiot that will do this...but I put the SqlDataSource definition outside the panel that contained the nested gridview it was attached to and wasted a day trying to figure out why it wouldn't work...
Other than my own stupid move - the example works great...exactly what I was looking for. Thanks.
Kris
Kris United States on 12/4/2008 7:43 PM Hi Mosa,
Your Article is very good but I need Expand ALL Items and collapse all items feature, Could u give code for that If u have.
Fergal
Fergal United Kingdom on 12/12/2008 6:13 PM Interesting article.

However, I have a situation where I would like a reversal of this situation:

I want to display a grid (or pseudo-grid) containing a summary of various details. When the user click on a row, I would like to expand the row to show a form containing the full information of the row. I would also like to give the users the ability to edit and update the individual records.

I've tried to create a custom control and add that into the expanded panel to do this (right now its a basic button that updates a label with the time when clicked. both wrapped in an updatepanel). However, when I click the button - although the event fires, the label doesnt update.

Do you have any idea why this is the case, and how to create the outer grid?
mosessaur
mosessaur Egypt on 12/14/2008 8:35 AM For thos who asked about Expand/Collapse all feature I made a demo about it and I'll post it between today and tomorrow.
Jai
Jai India on 1/3/2009 12:04 AM Hi

Could you please explain how we implement the multilevel master/details grid display using this. If possible could you please provide the sample code for the same.

Thanks
ahtisam
ahtisam United Kingdom on 1/17/2009 7:08 AM Hi Mosessaur .. Nice work I really like it and I am using this in my sample project... but I am facing one small problem which I know you can solve mate.
The issue is ....I am loading the checkbox in repeater control which can allow me to select which one I want to process further because the inner section is loaded through Ajax request so on the server side I can't able to find that checkbox object... I am stuck here can you please help me out

Best Regards &
Thanks for sharing this with us


Satinder
Satinder India on 2/14/2009 1:45 AM Hi Mose

this demo is fine,but i m trying somthing more,but i got problem i m binding second grid not with Sqldatasource but with dataset that i generate on some logic ,i m trying to display grid fields auto that have data (i have 40 fields but need to show only those that have data means feilds vary according uniqe no.),and in end i m doing auto sum of fields.

ok ,i have problem as i bind grid with dataset not with sqldatasource i got only first row of grid expand or collapse but remaining rows show data proprly but also show second grid with it.

plz tell how i bind .................
........................................
Ohhhhhh...........I did it .............

Plz see ........Just FOR UUUU MOSE

BUT
HOW I SHOW MY iMAGE........????
Ike
Ike United States on 2/15/2009 6:57 PM Great stuff.

Do you have an example on inserting new rows using the footer template in the child gridview?

I'm having an issue with pulling the input from the correct footer. I can only seem to pull the input from the last rendered child gridview. What am I missing?

Thanks in advance.
Txomin
Txomin Ireland on 2/23/2009 7:31 PM Hi Mosessaur,

Did you ever get the sample code for multigrouping from Iresh?

I spent a while trying to work it out but, haven;t had much luck...
Mohd Hyder Ali
Mohd Hyder Ali Oman on 3/11/2009 1:11 AM Dear Sir,

your article is cool,I have 3 table 1)Main Catogery 2)level1 and 3) Departments
Table Name:Catogery  
CatID
Cat_Name

Table : level1      
LevelID
CatID
Level_Name

Table Laughingepartments

Dept_ID
LevelID
DeptName

Now i wanted to display data using your example

CatName->Level_Name->Dept Name ( then grid view data).
Please help me how to do this,you have any code without using datasource.
Your assistance will be highly appreciated.
Praveen
Praveen United States on 4/18/2009 5:19 PM Hi Mosessaur,
      This is a very good article. you solved my one problem of displaying grid inside grid. however, I am facing an issue while reading the child gridview data on a button click event outside the grid. I am trying this way

protected void ButtonOnPageOutsideTheParentGrid_Click(object sender, EventArgs e)
{
  foreach (GridViewRow row in gvParent.Rows)
  {
    if (row.RowType == DataControlRowType.DataRow)
    {
        Panel pnlChild = (Panel)row.FindControl("pnlChild");
        GridView gvChild = (GridView)row.Cells[0].FindControl("gvChild");
        GridView gvChild1 = (GridView)row.FindControl("gvChild");
        GridView gvChild2 = (GridView)pnlCheckList.FindControl("gvChild");
        foreach (GridViewRow gridrow in gvCheckList.Rows)
        {
      CheckBox chkSelected = (CheckBox)gridrow.FindControl("chkSelected");

        }
        foreach (GridViewRow gridrow in gvCheckList1.Rows)
        {
      CheckBox chkSelected = (CheckBox)gridrow.FindControl("chkSelected");

        }
        foreach (GridViewRow gridrow in gvCheckList2.Rows)
          {
        CheckBox chkSelected = (CheckBox)gridrow.FindControl("chkSelected");

        }
    }
  }
}

all three approaches are finding Zero rows in the childgrid. Can you please help how to find child gridview data?

Thanks,
Praveen
Gavin
Gavin United States on 5/31/2009 2:25 AM Hey Moses,

This has been a great help - just one question though -

I would like to pass 2 params using RowCreated

    protected void gvContracts_RowCreated(object sender, EventArgs e)
    {
        // Response.Write(gvContracts.SelectedIndex);
        int contractId = (int)gvContracts.SelectedDataKey.Values["Contract_Id"];
        int contractMonth = (int)gvContracts.SelectedDataKey.Values["Contract_Month_Num"];
        GetChildTable(contractId, contractMonth);
    }

any clues for me??

Thanks,
Gavin
Dheeraj
Dheeraj United States on 8/3/2009 6:44 AM There is a mistake in your default.aspx. <columns> of GridView is improperly placed between </itemtemplate> and </asp:templatefield>. I am not able to get your look how much ever try. The expanded column is occupying the parent rows place and the parent row is going to the side of table
Mohammed Tanveer
Mohammed Tanveer Kuwait on 8/4/2009 11:44 PM Aswk,

Will you be able to demonstrate similar example using JSP.

-Tanveer
Muhammad Mosa
Muhammad Mosa Egypt on 8/5/2009 2:37 AM I am sorry, but I have limited experience with JSP

Pingbacks and trackbacks (3)+

Comments are closed