Hi kavithav,
You cant achieve what you are trying to do binding 6 tables with single gridview in TreeView Structure you need to take multiple gridview and simply hide and show them.
I have created a sample which full fill your requirement you need to modify the code according to your need.
I have used the Northwind Database Tables you can get Database from below link
Install the Northwind and Pubs Sample Databases in SQL Server Express
SQL
CREATE PROCEDURE SixTables
AS
BEGIN
SELECT TOP 10 CustomerID,CompanyName,ContactName FROM Customers
SELECT TOP 10 OrderID,CustomerID,EmployeeID,ShipVia,ShipCountry FROM Orders
SELECT TOP 10 * FROM [Order Details]
SELECT TOP 10 EmployeeID,FirstName,LastName,City,Country,Region,PostalCode FROM Employees
SELECT TOP 10 ProductID,ProductName,SupplierID,UnitPrice,ReorderLevel FROM Products
SELECT TOP 10 * FROM Students
END
GO;
HTML
<div>
<asp:GridView ID="gvMainGrid" runat="server" AutoGenerateColumns="false" OnRowDataBound="RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Main Grid">
<ItemTemplate>
<asp:ImageButton ID="imgMain" OnClick="ShowAndHideGrid" CommandArgument="Show" ImageUrl="images/plus.png"
runat="server" />
<asp:Panel ID="pnlMain" Visible="false" Style="position: relative" runat="server">
<table>
<tr>
<td>
<asp:ImageButton ID="imgFirst" OnClick="ShowAndHideGrid" CommandArgument="Show" ImageUrl="images/plus.png"
runat="server" />
<asp:Panel ID="pnlFirst" Visible="false" Style="position: relative" runat="server">
<asp:GridView ID="gvFirst" runat="server" />
</asp:Panel>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:ImageButton ID="imgSecond" OnClick="ShowAndHideGrid" CommandArgument="Show"
ImageUrl="images/plus.png" runat="server" />
<asp:Panel ID="pnlSecond" Visible="false" Style="position: relative" runat="server">
<asp:GridView ID="gvSecond" runat="server" />
</asp:Panel>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:ImageButton ID="imgThird" OnClick="ShowAndHideGrid" CommandArgument="Show" ImageUrl="images/plus.png"
runat="server" />
<asp:Panel ID="pnlThird" Visible="false" Style="position: relative" runat="server">
<asp:GridView ID="gvThird" runat="server" />
</asp:Panel>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:ImageButton ID="imgFourth" OnClick="ShowAndHideGrid" CommandArgument="Show"
ImageUrl="images/plus.png" runat="server" />
<asp:Panel ID="pnlFourth" Visible="false" Style="position: relative" runat="server">
<asp:GridView ID="gvFourth" runat="server" />
</asp:Panel>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:ImageButton ID="imgFifth" OnClick="ShowAndHideGrid" CommandArgument="Show" ImageUrl="images/plus.png"
runat="server" />
<asp:Panel ID="pnlFifth" Visible="false" Style="position: relative" runat="server">
<asp:GridView ID="gvFifth" runat="server" />
</asp:Panel>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:ImageButton ID="imgSix" OnClick="ShowAndHideGrid" CommandArgument="Show" ImageUrl="images/plus.png"
runat="server" />
<asp:Panel ID="pnlSixth" Visible="false" Style="position: relative" runat="server">
<asp:GridView ID="gvSixth" runat="server" />
</asp:Panel>
</td>
<td>
</td>
</tr>
</table>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Dummy");
dt.Rows.Add();
gvMainGrid.DataSource = dt;
gvMainGrid.DataBind();
}
}
protected void RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataSet ds = BindDataSet();
GridView gvFirst = e.Row.FindControl("gvFirst") as GridView;
GridView gvSecond = e.Row.FindControl("gvSecond") as GridView;
GridView gvThird = e.Row.FindControl("gvThird") as GridView;
GridView gvFourth = e.Row.FindControl("gvFourth") as GridView;
GridView gvFifth = e.Row.FindControl("gvFifth") as GridView;
GridView gvSixth = e.Row.FindControl("gvSixth") as GridView;
gvFirst.DataSource = ds.Tables[0];
gvFirst.DataBind();
gvSecond.DataSource = ds.Tables[1];
gvSecond.DataBind();
gvThird.DataSource = ds.Tables[2];
gvThird.DataBind();
gvFourth.DataSource = ds.Tables[3];
gvFourth.DataBind();
gvFifth.DataSource = ds.Tables[4];
gvFifth.DataBind();
gvSixth.DataSource = ds.Tables[5];
gvSixth.DataBind();
}
}
protected void ShowAndHideGrid(object sender, EventArgs e)
{
ImageButton imgBtn = (sender as ImageButton);
if (imgBtn.ID == "imgMain")
{
Panel pnlMain = ((imgBtn.NamingContainer as GridViewRow).FindControl("pnlMain") as Panel);
if (imgBtn.CommandArgument == "Show")
{
pnlMain.Visible = true;
imgBtn.ImageUrl = "images/minus.png";
imgBtn.CommandArgument = "Hide";
}
else
{
pnlMain.Visible = false;
imgBtn.ImageUrl = "images/plus.png";
imgBtn.CommandArgument = "Show";
}
}
if (imgBtn.ID == "imgFirst")
{
Panel pnlMain = ((imgBtn.NamingContainer as GridViewRow).FindControl("pnlFirst") as Panel);
if (imgBtn.CommandArgument == "Show")
{
pnlMain.Visible = true;
imgBtn.ImageUrl = "images/minus.png";
imgBtn.CommandArgument = "Hide";
}
else
{
pnlMain.Visible = false;
imgBtn.ImageUrl = "images/plus.png";
imgBtn.CommandArgument = "Show";
}
}
if (imgBtn.ID == "imgSecond")
{
Panel pnlMain = ((imgBtn.NamingContainer as GridViewRow).FindControl("pnlSecond") as Panel);
if (imgBtn.CommandArgument == "Show")
{
pnlMain.Visible = true;
imgBtn.ImageUrl = "images/minus.png";
imgBtn.CommandArgument = "Hide";
}
else
{
pnlMain.Visible = false;
imgBtn.ImageUrl = "images/plus.png";
imgBtn.CommandArgument = "Show";
}
}
if (imgBtn.ID == "imgThird")
{
Panel pnlMain = ((imgBtn.NamingContainer as GridViewRow).FindControl("pnlThird") as Panel);
if (imgBtn.CommandArgument == "Show")
{
pnlMain.Visible = true;
imgBtn.ImageUrl = "images/minus.png";
imgBtn.CommandArgument = "Hide";
}
else
{
pnlMain.Visible = false;
imgBtn.ImageUrl = "images/plus.png";
imgBtn.CommandArgument = "Show";
}
}
if (imgBtn.ID == "imgFourth")
{
Panel pnlMain = ((imgBtn.NamingContainer as GridViewRow).FindControl("pnlFourth") as Panel);
if (imgBtn.CommandArgument == "Show")
{
pnlMain.Visible = true;
imgBtn.ImageUrl = "images/minus.png";
imgBtn.CommandArgument = "Hide";
}
else
{
pnlMain.Visible = false;
imgBtn.ImageUrl = "images/plus.png";
imgBtn.CommandArgument = "Show";
}
}
if (imgBtn.ID == "imgFifth")
{
Panel pnlMain = ((imgBtn.NamingContainer as GridViewRow).FindControl("pnlFifth") as Panel);
if (imgBtn.CommandArgument == "Show")
{
pnlMain.Visible = true;
imgBtn.ImageUrl = "images/minus.png";
imgBtn.CommandArgument = "Hide";
}
else
{
pnlMain.Visible = false;
imgBtn.ImageUrl = "images/plus.png";
imgBtn.CommandArgument = "Show";
}
}
if (imgBtn.ID == "imgSix")
{
Panel pnlMain = ((imgBtn.NamingContainer as GridViewRow).FindControl("pnlSixth") as Panel);
if (imgBtn.CommandArgument == "Show")
{
pnlMain.Visible = true;
imgBtn.ImageUrl = "images/minus.png";
imgBtn.CommandArgument = "Hide";
}
else
{
pnlMain.Visible = false;
imgBtn.ImageUrl = "images/plus.png";
imgBtn.CommandArgument = "Show";
}
}
}
private DataSet BindDataSet()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("SixTables");
SqlDataAdapter sda = new SqlDataAdapter();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds);
return ds;
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dt As New DataTable()
dt.Columns.Add("Dummy")
dt.Rows.Add()
gvMainGrid.DataSource = dt
gvMainGrid.DataBind()
End If
End Sub
Protected Sub RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ds As DataSet = BindDataSet()
Dim gvFirst As GridView = TryCast(e.Row.FindControl("gvFirst"), GridView)
Dim gvSecond As GridView = TryCast(e.Row.FindControl("gvSecond"), GridView)
Dim gvThird As GridView = TryCast(e.Row.FindControl("gvThird"), GridView)
Dim gvFourth As GridView = TryCast(e.Row.FindControl("gvFourth"), GridView)
Dim gvFifth As GridView = TryCast(e.Row.FindControl("gvFifth"), GridView)
Dim gvSixth As GridView = TryCast(e.Row.FindControl("gvSixth"), GridView)
gvFirst.DataSource = ds.Tables(0)
gvFirst.DataBind()
gvSecond.DataSource = ds.Tables(1)
gvSecond.DataBind()
gvThird.DataSource = ds.Tables(2)
gvThird.DataBind()
gvFourth.DataSource = ds.Tables(3)
gvFourth.DataBind()
gvFifth.DataSource = ds.Tables(4)
gvFifth.DataBind()
gvSixth.DataSource = ds.Tables(5)
gvSixth.DataBind()
End If
End Sub
Protected Sub ShowAndHideGrid(sender As Object, e As EventArgs)
Dim imgBtn As ImageButton = TryCast(sender, ImageButton)
If imgBtn.ID = "imgMain" Then
Dim pnlMain As Panel = TryCast(TryCast(imgBtn.NamingContainer, GridViewRow).FindControl("pnlMain"), Panel)
If imgBtn.CommandArgument = "Show" Then
pnlMain.Visible = True
imgBtn.ImageUrl = "images/minus.png"
imgBtn.CommandArgument = "Hide"
Else
pnlMain.Visible = False
imgBtn.ImageUrl = "images/plus.png"
imgBtn.CommandArgument = "Show"
End If
End If
If imgBtn.ID = "imgFirst" Then
Dim pnlMain As Panel = TryCast(TryCast(imgBtn.NamingContainer, GridViewRow).FindControl("pnlFirst"), Panel)
If imgBtn.CommandArgument = "Show" Then
pnlMain.Visible = True
imgBtn.ImageUrl = "images/minus.png"
imgBtn.CommandArgument = "Hide"
Else
pnlMain.Visible = False
imgBtn.ImageUrl = "images/plus.png"
imgBtn.CommandArgument = "Show"
End If
End If
If imgBtn.ID = "imgSecond" Then
Dim pnlMain As Panel = TryCast(TryCast(imgBtn.NamingContainer, GridViewRow).FindControl("pnlSecond"), Panel)
If imgBtn.CommandArgument = "Show" Then
pnlMain.Visible = True
imgBtn.ImageUrl = "images/minus.png"
imgBtn.CommandArgument = "Hide"
Else
pnlMain.Visible = False
imgBtn.ImageUrl = "images/plus.png"
imgBtn.CommandArgument = "Show"
End If
End If
If imgBtn.ID = "imgThird" Then
Dim pnlMain As Panel = TryCast(TryCast(imgBtn.NamingContainer, GridViewRow).FindControl("pnlThird"), Panel)
If imgBtn.CommandArgument = "Show" Then
pnlMain.Visible = True
imgBtn.ImageUrl = "images/minus.png"
imgBtn.CommandArgument = "Hide"
Else
pnlMain.Visible = False
imgBtn.ImageUrl = "images/plus.png"
imgBtn.CommandArgument = "Show"
End If
End If
If imgBtn.ID = "imgFourth" Then
Dim pnlMain As Panel = TryCast(TryCast(imgBtn.NamingContainer, GridViewRow).FindControl("pnlFourth"), Panel)
If imgBtn.CommandArgument = "Show" Then
pnlMain.Visible = True
imgBtn.ImageUrl = "images/minus.png"
imgBtn.CommandArgument = "Hide"
Else
pnlMain.Visible = False
imgBtn.ImageUrl = "images/plus.png"
imgBtn.CommandArgument = "Show"
End If
End If
If imgBtn.ID = "imgFifth" Then
Dim pnlMain As Panel = TryCast(TryCast(imgBtn.NamingContainer, GridViewRow).FindControl("pnlFifth"), Panel)
If imgBtn.CommandArgument = "Show" Then
pnlMain.Visible = True
imgBtn.ImageUrl = "images/minus.png"
imgBtn.CommandArgument = "Hide"
Else
pnlMain.Visible = False
imgBtn.ImageUrl = "images/plus.png"
imgBtn.CommandArgument = "Show"
End If
End If
If imgBtn.ID = "imgSix" Then
Dim pnlMain As Panel = TryCast(TryCast(imgBtn.NamingContainer, GridViewRow).FindControl("pnlSixth"), Panel)
If imgBtn.CommandArgument = "Show" Then
pnlMain.Visible = True
imgBtn.ImageUrl = "images/minus.png"
imgBtn.CommandArgument = "Hide"
Else
pnlMain.Visible = False
imgBtn.ImageUrl = "images/plus.png"
imgBtn.CommandArgument = "Show"
End If
End If
End Sub
Private Function BindDataSet() As DataSet
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim con As New SqlConnection(constr)
Dim cmd As New SqlCommand("SixTables")
Dim sda As New SqlDataAdapter()
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
sda.SelectCommand = cmd
Dim ds As New DataSet()
sda.Fill(ds)
Return ds
End Function
ScreenShot