Click here to Skip to main content
Click here to Skip to main content

Editable Nested GridView (All-in-One)

By , 16 Aug 2007
 

Screenshot - EditNestedGridView.jpg

Introduction

This article explains how to make an ASP.NET editable nested GridView. Here I am going to explain how to provide all the features of Edit/Add/Delete/Update/Page/Sort of a GridView, and not only one GridView, but I am going to explain how to extend these features to even nested grids (GridView inside GridView). I have provided the fully functional source code, which is self-explanatory.

Background

My previous article explains about the features of nested editable DataGrids. This article provides all those features in a GridView (Visual Studio 2005, .NET 2.0). With the combination of GridView and DataSource controls, it's very easy to create an editable GridView.

Using the Code

This is a web application with a virtual directory named EditNestedGridView. You may create the same virtual directory to run this application with Visual Studio .NET 2005, or create any other virtual directory and map the path to this directory to access it from the browser. As I have used Access 2003 as my database, you need to have Microsoft Access installed on your machine. I have used the NorthWind database with some modifications. I have also included this in the code bundle under the App_Data folder. I have used C# for the code-behind files. In Visual Studio 2005, File --> Open --> Web Site, and navigate to the folder EditNestedGridView.

Step-by-Step Procedure

The code attached is self-explanatory, but I will try to explain it as much as possible.

  1. Since here I am going to use the DataSource control, let's first create an AccessDataSource control as below:
  2. <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
        DataFile="App_Data/Northwind.mdb" 
        SelectCommand="SELECT [Customers].[CustomerID], 
        [Customers].[CompanyName],[Customers].[ContactName],
        [Customers].[ContactTitle],[Customers].[Address] FROM [Customers] 
        ORDER BY [Customers].[CustomerID]"></asp:AccessDataSource>

    The main advantage of the DataSource control is that it simplifies the amount of custom code that needs to be written to retrieve and bind data, and even to sort, page through, or edit data.

  3. Now, let's create a simple GridView control and attach the previously created DataSource control as shown below:
  4. <asp:GridView ID="GridView1" AllowPaging="True" BackColor="#f1f1f1" 
                AutoGenerateColumns=false DataSourceID="AccessDataSource1" 
                DataKeyNames="CustomerID"
                style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 32px" 
                ShowFooter=true Font-Size=Small
                Font-Names="Verdana" runat="server" GridLines=None BorderStyle=Outset>

    GridView is very similar to DataGrid and it has all those column features of DataGrid like TemplateColumn, BoundColumn to populate data as columns. EditItemTemplate and FooterTemplate can be used for editing and adding purposes. The following code shows the columns of the parent grid:

    <asp:TemplateField HeaderText="Customer ID" SortExpression="CustomerID">
        <ItemTemplate>
            <asp:Label ID="lblCustomerID" Text='<%# Eval("CustomerID") %>' 
                runat="server"></asp:Label>
        </ItemTemplate>
        <EditItemTemplate>
            <asp:Label ID="lblCustomerID" Text='<%# Eval("CustomerID") %>' 
                runat="server"></asp:Label>
        </EditItemTemplate>
        <FooterTemplate>
            <asp:TextBox ID="txtCustomerID" Text='' runat="server"></asp:TextBox>
        </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Company Name" SortExpression="CompanyName">
        <ItemTemplate><%# Eval("CompanyName") %></ItemTemplate>
        <EditItemTemplate>
            <asp:TextBox ID="txtCompanyName" Text='<%# Eval("CompanyName") %>' 
                runat="server"></asp:TextBox>
        </EditItemTemplate>
        <FooterTemplate>
            <asp:TextBox ID="txtCompanyName" Text='' runat="server"></asp:TextBox>
        </FooterTemplate>
    </asp:TemplateField>
    ..........................
    ..........................
    
    <asp:CommandField HeaderText="Edit" ShowEditButton="True" />
    <asp:TemplateField HeaderText="Delete">
        <ItemTemplate>
            <asp:LinkButton ID="linkDeleteCust" CommandName="Delete" 
                runat="server">Delete</asp:LinkButton>
        </ItemTemplate>
        <FooterTemplate>
            <asp:LinkButton ID="linkAddCust" CommandName="AddCustomer" 
                runat="server">Add</asp:LinkButton>
        </FooterTemplate>
    </asp:TemplateField>

    Now that we have all the columns in place, we need the event handlers to take care of the Add/Edit/Delete actions. Handling these events is very straightforward compared to that for the DataGrid. The DataSource control takes care of the paging and sorting actions. Here is the final parent GridView control with all these events.

    <asp:GridView ID="GridView1" AllowPaging="True" BackColor="#f1f1f1" 
                AutoGenerateColumns=false DataSourceID="AccessDataSource1" 
                DataKeyNames="CustomerID"
                style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 32px" 
                ShowFooter=true Font-Size=Small
                Font-Names="Verdana" runat="server" GridLines=None 
                OnRowDataBound="GridView1_RowDataBound" 
                OnRowCommand = "GridView1_RowCommand" 
                OnRowUpdating = "GridView1_RowUpdating" BorderStyle=Outset
                OnRowDeleting = "GridView1_RowDeleting" 
                OnRowDeleted = "GridView1_RowDeleted"
                OnRowUpdated = "GridView1_RowUpdated" AllowSorting=true>

    With all the above options, the GridView looks like:

    Screenshot - EditNestedGridView1.jpg

  5. Until now, we have created a parent GridView. Now we are going to extend these features in a child GridView as well.
  6. Before adding another GridView, we must understand how GridView emits its content as HTML tags. For an Internet Explorer browser, GridView is like a regular Table with TR and TD tags. So, if we can manipulate the parent GridView to forcibly close a row and emit a child GridView as another row, we are done with it.

    What is displayed is some HTML table cell and row tags that effectively intercept the current output that will be generated by the GridView with our own special implementation. Namely, we are telling the table (when it's drawn) to close the current cell, the current row, and now add a new row with one blank column (for spacing) and another column (spanning all columns) that we'll use to display a second GridView. Here is the piece of code which explains this:

    <asp:TemplateField>
        <ItemTemplate>
            <tr>
            <td colspan="100%">
            <div id="div<%# Eval("CustomerID") %>" 
                style="display:none;position:relative;left:15px;OVERFLOW: auto;WIDTH:97%" >

    Here, I have created a division id="div Eval("CustomerID") with an ID of Customer (parent row) which holds the child GridView so that we can dynamically hide and expand it by using the DIV ID. Also, we need a column in the main GridView which holds the image to expand and collapse the child GridView as below:

    <asp:TemplateField>
        <ItemTemplate>
            <a href="javascript:expandcollapse('div<%# Eval("CustomerID") %>', 'one');">

    Here, the JavaScript function expandcollapse will take care of the expand and collapse action.

  7. In order to bind the child GridView, we can't use the static DataSource control as we have used for the parent GridView. We will have to dynamically prepare the query based on the customer ID of the corresponding parent row, and that we can do it in the RowDataBound event of the parent grid as below:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        GridViewRow row = e.Row;
        string strSort = string.Empty;
    
        // Make sure we aren't in header/footer rows
        if (row.DataItem == null)
        {
            return;
        }
    
        //Find Child GridView control
        GridView gv = new GridView();
        gv = (GridView)row.FindControl("GridView2");
    
        //Prepare the query for Child GridView by passing 
        //the Customer ID of the parent row
        gv.DataSource = 
            ChildDataSource(((DataRowView)e.Row.DataItem)["CustomerID"].ToString(), 
            strSort);
        gv.DataBind();
    }

    Here, the ChildDataSource function forms the query using the passed customer ID and returns the AccessDataSource.

  8. Now, we have data in the child grid as well, with dynamic expand and collapse. Let's add the effects one by one as we did for the parent grid. However, before going further, there is a little tricky part involved. In the case of the parent grid, there is only a unique ID (GridView1), and in the case of the child, there will be several unique IDs that get generated at run time. If we can identify the one which we need, that will solve this problem.

    Paging and sorting were taken care of by the DataSource control in the case of the parent grid. For the child grid, we have to take care of it manually using the corresponding events PageIndexChanging and Sorting. A sample code of the paging event looks like:

    protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView gvTemp = (GridView)sender;
        gvUniqueID = gvTemp.UniqueID;
        gvNewPageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }

    Here, we have identified the run time unique ID of the child grid which needs paging along with the new page number. We are going to use these variable values in the RowDataBound event of the parent grid, as below:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        ........................
        //Find Child GridView control
        GridView gv = new GridView();
        gv = (GridView)row.FindControl("GridView2");
        //Check if any additional conditions (Paging, Sorting, Editing, etc) 
        //to be applied on child GridView
        if (gv.UniqueID == gvUniqueID)
        {
            gv.PageIndex = gvNewPageIndex;
            gv.EditIndex = gvEditIndex;
            //Check if Sorting used
            if (gvSortExpr != string.Empty)
            {
                GetSortDirection();
                strSort = " ORDER BY " + string.Format("{0} {1}", gvSortExpr, gvSortDir);
            }
            //Expand the Child grid
            ClientScript.RegisterStartupScript(GetType(), "Expand", 
                "<script language="javascript"></script>");
        }
        ..........................
    }

The remaining actions (Sorting/Edit/Update/Delete) can also be handled similarly to paging. Refer to the source code attached above.

Conclusion

The GridView has more features compared to the DataGrid, which will make it easier to code, and also, we can include HTML tags in between for more flexibility.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Veera V Satya N Kanithi
Architect
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionSetting the column sizesmemberMember 1001832414 May '13 - 9:01 
Hi,
 
I'm using this code and think it is fantastic! One thing I can't figure out is how to change the column widths, as I have added many and they are spanning 2 monitors.
 
Does anyone have an idea?
Questioneditable nested grid ..problem in nested gridmemberMember 92501388 Apr '13 - 1:59 
hello sir,
 
parent grid is updated and deleted but i am unable to write the same code in row cancelling and row editing in the nested grid which is child grid.
 
please help me for this....
 
protected void gvchild_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView gvtemp = (GridView)sender;
gvUniqueId = gvtemp.UniqueID;
gvEditIndex = e.NewEditIndex;
gvparent.DataBind();
}
 
this is the code what i wrote...
please help me in this i am not edit the row...
GeneralMy vote of 5membersupriya chaladi15 Mar '13 - 22:29 
thing i am searching for
QuestionHow then can you add a search button?memberSithelo Ngwenya8 Mar '13 - 2:04 
How do you add a search botton and show the nested gridview after search button is clicked?
GeneralExcellent workmemberSithelo Ngwenya8 Mar '13 - 1:34 
I just tested it and have nothing to say but appreciation. Keep up the good work. I am working to implement this on MVC.
QuestionBinds to LAST item for GridView2...Help Please...almost there!memberdburns234 Dec '12 - 15:53 
I bind to a datasource for gridview2.
 
the grid shows up, but shows items for the last item in gridview1 and not the item I click on.
so, if I click on item 6, it shows item 10, click on item 8, it shows for item 10...
 
Is there a way around this?
QuestionAWESOMEEEEmemberMember 964389230 Nov '12 - 0:02 
Thumbs Up | :thumbsup:
Questionvb.net codememberMember 430984518 Nov '12 - 2:07 
can i get this vb.net code, so that i can use it in my project.
i am purely don't know anything about web.
GeneralMy vote of 5memberbatz099 Nov '12 - 4:13 
simply great
GeneralMy vote of 5memberS Devrajani1 Oct '12 - 10:52 
It has all events that i was looking for. Thanks for helping me by this article.
GeneralMy vote of 5memberasp_crazy_guy24 Sep '12 - 0:36 
Excellent information.
Questionits working but parentgrid and nested grid is merging after the events are firing in the nested gridmemberMember 888706330 Aug '12 - 1:48 
i placed entire code in updatepanel,it's simply merging after every event but working to view the events i have to press + symbol every time to view how to stop merging
 

Thanks in advance
Naseer
QuestionPopulate Nested Data After DeletememberODunk5 Jun '12 - 5:50 
How do you go about populating the nested data after you delete a row? I added snippets of the code to my code to get the delete to work and when I click the delete link it drops back to the parent grid. I would like the nested grid to stay open.
 
Is this possible?
 
Thanks!
 
Shawn
QuestionNested GridView with multiple childgrdismemberdilfizo3 Apr '12 - 22:47 
Hello Sir,can it possible to n number of child grid in parent grid..my urgent requirement is that parent grid and child grid but child grid must be more than 3/4 grids with full functionality like treeview grid .plz help me out sir..thanx in advance..
QuestionUrgent Querymemberdilfizo2 Apr '12 - 3:02 
Hello Sir,can it possible to n number of child grid in parent grid..my urgent requirement is that parent grid and child grid but child grid must be more than 3/4 grids with full functionality like treeview grid .plz help me out sir..thanx in advance..
QuestionThank youmemberTrong Thao5 Mar '12 - 16:34 
Hi Satya Kanithi
Thank you very mush!
GeneralMy vote of 5membersanamshaikh2 Jan '12 - 19:00 
Thanks alot its working perfect!! it really helped me alot
GeneralMy vote of 5memberjeevesh pandey5 Dec '11 - 5:10 
excellent..
GeneralMy vote of 5memberVHK-DEV24 Aug '11 - 1:24 
Excellent Article
GeneralMy vote of 5memberDilip Baboo15 Jul '11 - 10:35 
Nice !
GeneralSqlDatasourcememberMember 784423115 Apr '11 - 5:00 
Hi, this article is very usefull for me, there is only 1 problem. I use SQLdata Server & I don't know what parts of code I have to adjust to make it work properly.
Any possible help with this would be appreciated ! Thanks.
GeneralRe: SqlDatasourcememberDenDries15 Apr '11 - 8:57 
Hi, here's an example:
 
    private DataTable ChildDataSource(string strCustometId, string strSort)
    {
        using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Evaluatie"].ConnectionString))
        {
            conn.Open();
            using (SqlDataAdapter a = new SqlDataAdapter("SELECT criteriaid, domeinid, omschrijving FROM criteria WHERE criteria.domeinid=" + strCustometId + " UNION ALL SELECT '" + strCustometId + "','','' FROM criteria WHERE criteria.domeinid=" + strCustometId + " HAVING COUNT(*)=0 " + strSort, conn))
            {
                DataTable dt = new DataTable();
                a.Fill(dt);
                return dt;
            }
        }
    }

GeneralRe: SqlDatasourcememberMember 784423115 Apr '11 - 10:48 
This worked very well thanks ! Btw did you find a way or a example on your earlyer question ? The one where you aked for a third Gridview nested ? It might proof usefull to me in the future. Cheers !
GeneralRe: SqlDatasourcememberDenDries15 Apr '11 - 21:16 
No problem!
 
I'm still having some issues implementing the third gridview. Contacting the author also didn't seem to help.
 
I've described my problem here:
http://forums.asp.net/t/1673163.aspx/1?+Javascript+ASP+expand+collapse+nested+gridview[^]
 
Maybe you can take a look at it? Smile | :)
GeneralRe: SqlDatasourcememberMember 78442316 May '11 - 7:31 
Hey, I wasn't able to check your post in time sadly, however you seem to have found a solution to your problem.
I tryed working around your information given on the site. but somehow it ain't working.
Would it be possible for you to send me the files or complete code ?
This might acctually be usefull for my realisations.
 
Thanks again ! You seem to be knowing better what your doing then me !
GeneralRe: SqlDatasourcememberDenDries7 May '11 - 3:31 
Sure !
 
The only problem I'm still experiencing is that after every page load, the javascript is reloaded so all the gridviews are collapsed. (For example after editing a row). I haven't figured it out how to solve that...
 
The gridhowever is working just fine. Smile | :)
 
You can download it here:
http://gridview.degendt.com/[^]
 
note: I didn't have the time to translate everything, but I don't think that is necessary. The first grid is called "domein", the second one "Criteria" and the third one "SubCriteria"
 
Let me know if you need my help !
GeneralRe: SqlDatasourcemembercas200028 May '12 - 2:47 
I was having the same problem (all the gridviews are collapsed), the only difference with my code was an update panel, after I removed it, it started to work ok.
GeneralGood C# example with third gridviewmemberDenDries8 Apr '11 - 0:47 
I realise this article is 'old' but I was wondering if anyone could supply me a good example with a third, nested gridview? Thanks!
GeneralMy vote of 5membershailendraimr22 Mar '11 - 0:29 
wow gud work
GeneralNot Insertingmembersharathu78 Jan '11 - 18:31 
I have used this code for creating Editable Nested GridView (All-in-One) for my website. But i am not able to insert values to the child gridview. Its just refreshes the page and does not show any error pages when i click add button of child grid, and the value is not inserted. Here is my page code... please help me...
 
http://www.codeproject.com/Questions/144121/Nested-GridView-Child-Grid-Not-Inserting.aspx[^]
Cooooooooooool !

GeneralNice articlemembervallibhuvan28 Sep '10 - 8:33 
Nice Article Satya. Its helping me a lot. Thank you.
GeneralChildgrid wont display in parentmembermarine887 Sep '10 - 9:02 
The childgrid gets data but won't display in parent grid???
QuestionDo with Stored Proc and not inline sql?membermarine887 Sep '10 - 4:31 
I am trying this with a stored proc and not inline sql but for some reason my 1st result is in the parent grid but all my child results are outside of the parent so my expand and contract do not contain the child. In addition the following parent headers are all not formatted like the very first one. I can provide images if anybody can help.
 
Thanks,
GeneralI have repeated rows in my nested gridgroupGauravGupta21220 Jul '10 - 20:35 
Hii EveryOne
 
I would like to say that the article is really great.I learns lot from the article. But i am facing from one problem i have the repeated rows in child grid when second child grid add.Above child grid rows add dynamically in the below child grid.As if i have Id h001 and h002 in first childgrid rows now when second child grid comes which has only h003 Id . But at run time i found h001,h002and h003 in second child grid. h001and h002 comes from the above child grid.
 
Please suggest me where i am doing wrong.
 
Thanks
Gaurav Gupta
GeneralExcellent extension!memberplanetregin14 Jul '10 - 4:26 
Great job and explanation! Clean and easy code. Thanks!
QuestionPostback errormemberKHolum28 Jun '10 - 12:21 
Your code is fantastic. I have actually modified it to allow for double click row event and other visual asthetics. However, I am not sure why I am receiving a Postback error when I perform the DoubleClick on the row. If I set EnableEventValidation to False, the error goes away. Since this opens us up to possible injection attacks, I want to leave it as True.
I added the following column and programmatically set visible to False.
<asp:ButtonField Text="DoubleClick" CommandName="DoubleClick" />
 
I added the following code to the bottom of GridView1_RowDataBound event handler:
// Get the LinkButton control in the second cell
LinkButton _doubleClickButton = (LinkButton)e.Row.Cells[1].Controls[0];
// Get the javascript which is assigned to this LinkButton
string _jsDouble =
ClientScript.GetPostBackClientHyperlink(_doubleClickButton, "");
// Add this javascript to the ondblclick Attribute of the row
e.Row.Attributes["ondblclick"] = _jsDouble;

_doubleClickButton.Visible = false;

 
Then I added the following Render event:
protected override void Render(HtmlTextWriter writer)
{
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
// validate the controls event
Page.ClientScript.RegisterForEventValidation(row.UniqueID + "$ctl0");
}
}
base.Render(writer);
}
 

I have been online checking posts for hours and trying various examples but I can't seem to figure out why I receive the following error message:
 
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
 
If anyone could help, that would be great! I am not a novice programmer but I am a newbie to ASP.Net. Any help would be appreciated.
Kristin

QuestionImages while Sorting Master and Child Gridview?memberPawan Kiran11 Jun '10 - 3:09 
Hi
 
Your article simple fine,
in additional i want to show some image while sorting the gridview
 
like for ascending show one image,decending show another image
same for child gridview also..
 
have any idea, please let me know..
 

Regards,
Pawan.
GeneralcollapsememberAlexGatin21 Oct '09 - 0:24 
How do I expand and collapse all?
GeneralRe: collapsememberAlexGatin21 Oct '09 - 0:26 
How do download source files ?
Generalgridview checkboxfiledmemberallanrai21 Sep '09 - 1:12 
hi i need to implement a 2checkboxfiled in   gridview if one check yes checkboc then der should call a funtion ...example      if one click yes than (exit+1)-entry..esle (exit- entry).....so how can i make it .plz help.me.....out...
GeneralNeed help for retrieving nodes from XML Menu Files stored onto the Sql server using Sqldatasourcememberbrightsy_mary17 Sep '09 - 19:42 
Hi, Iam a newbie completly new to .Net .
First i want to say thanks for such a great article , learned a lot from it about Nested gridviews, Expand/Collapse, Edit Update etc.
 
But I want to the same for Xml Menu Files stored in an Sql Server DB. For the Xml Menu Files created from another Page.
I want to get the Nodes dynamically, i.e. I have to display nested gridviews for more than one Xml Menu File, so I cant bind the nodes statically.
 
Can you help me pls???
 
vry urgent....Confused | :confused:
 
Regards
 
Brightsy
GeneralNo Records Bound to the Gridview, can't add .memberMember 366494717 Sep '09 - 5:12 
sample OK. but gridview use new table. No Records Bound to the Gridview.
gridview is no display ? (include FooterTemplate).
how to do.
GeneralADO.NETgroupseoamitk7 Aug '09 - 23:55 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
OleDbCommandBuilder cmb;
OleDbConnection connection;
OleDbDataAdapter adapter;
DataSet ds;
OleDbCommand command;
public Form1()
{
connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/Hotel.mdb");
InitializeComponent();
}
 

 
private void Form1_Load(object sender, EventArgs e)
{

connection.Open();
command = new OleDbCommand("select *from Banqute_Booking",connection);
adapter= new OleDbDataAdapter(command);
cmb= new OleDbCommandBuilder(adapter);
ds = new DataSet();
adapter.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
connection.Close();
}
private void button1_Click(object sender, EventArgs e)
{
connection.Open();
adapter.Update(ds);
connection.Close();
}
 
private void button2_Click(object sender, EventArgs e)
{
connection.Open();
command = new OleDbCommand("select *from Banqute_Booking where Booking_Date_For=@id", connection);
command.Parameters.Add(new OleDbParameter("@id", dateTimePicker1.Text));
adapter = new OleDbDataAdapter(command);
cmb = new OleDbCommandBuilder(adapter);
ds = new DataSet();
adapter.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
connection.Close();
}
}
}
 

 
In this code if i am updating my record without filtering the data it's working but if put any condition on my command it give an exception.
 
Bring me out of it.
GeneralMy vote of 1memberamittrivedimca4 Jul '09 - 1:47 
code works but table structure becomes broken after rendering grid.
GeneralSorting in Second GridViewmembersukhjinder200922 Jun '09 - 6:41 
Hi,
 
We are using the NestedGridView, and when we sort on the child grid on any of the columns of the child grid by clicking on them, the parent grid refreshes and the child grid collapses. We need to have the sorting on the child grid independently sorting only records in the child grid and remaining expanded.
 
We also lose the plus sign for the child grid when sorting the parent grid.
 
Sincerely,
Sukh
Generalnice work [modified]memberMrKhalid21 Jun '09 - 8:55 
nice work.
 
How did you add the 2nd gridview? I mean, do you visually see gridview2 at design time? If not, how would you add the related events to GridView2 such as RowDataBound, RowCommand, SelectedIndexChanged etc?
 
I tried to get GridView2 out of GridView1 and created all needed events and then put it back in its place, but same I get Compilation Error not recognizing GridView2 events.
 
See below
Compilation Error
 
Compiler Error Message: BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
 
Source Error:
Line 113: Protected Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound
Line 114:
Line 115: End Sub

 

Anyone, please help.
 
I am using VB code.
Thanks
 
ILoveMicrosoft!!

GeneralChildgrid Sortmemberdoran_doran7 Jun '09 - 17:57 
The sort on the childgrid is not working; nothing happens when I click on the each column header for sort. I uploaded all three files (default.aspx, default.aspx.cs, and the javascript file). Please suggest.
 
http://www.superboxhost.com/genericfiles/post.txt
GeneralExpand/Collapse allmemberMember 28890133 Jun '09 - 18:40 
How do I expand and collapse all?
GeneralRe: Expand/Collapse allmemberinetfly12326 Aug '09 - 4:45 
add this right after the form tag:
<div style="">
	<a id="a" href="#" onclick="<%= sbExpandLink.ToString() %>return(false);">[toggle all expansion]</a>
</div>
 
Add this into the "Variables" region:
protected StringBuilder sbExpandLink = new System.Text.StringBuilder("");
 
And finally, add this to the end of the "GridView1_RowDataBound" event handler:
sbExpandLink.Append("expandcollapse('div" + ((DataRowView)e.Row.DataItem)["CustomerID"].ToString() + "', 'one');");

 

GeneralRe: Expand/Collapse allmemberdoran_doran17 Sep '09 - 2:52 
1. I put the div code after the </form>.
2. I put the stringbuilder sbexpandlink in the default.aspx and default.aspx.cs file
3. I added the last code in the gridview1_rowdatabound (I added in addition to the existing code, did not replace with yours).
 
But not working. Please suggest.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 17 Aug 2007
Article Copyright 2007 by Veera V Satya N Kanithi
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid