Showing posts with label Inner Grid. Show all posts
Showing posts with label Inner Grid. Show all posts

Monday, June 16, 2014

Inner Grid

.CS CODE

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Grid.aspx.cs" Inherits="Grid" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="GVOuterGrid" runat="server" AutoGenerateColumns="false" OnRowDataBound="GVOuterGrid_RowDataBound" DataKeyNames="Empid">
    <Columns>
    <asp:TemplateField HeaderText="Name">
    <ItemTemplate>
    <asp:Label ID="lblDepId" runat="server" Text='<%# Bind("Empname")%>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Designation">
    <ItemTemplate>
    <asp:Label ID="lblDepName" runat="server" Text='<%# Bind("designation")%>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>



    <asp:TemplateField HeaderText="Details">
    <ItemTemplate>
    <asp:GridView ID="GVinnerGrid" runat="server" AutoGenerateColumns="false">
    <Columns>
    <asp:TemplateField HeaderText="Employee ID">
    <ItemTemplate>
    <asp:Label ID="lblEmpId" runat="server" Text='<%# Bind("address")%>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Employee Name">
    <ItemTemplate>
    <asp:Label ID="lblEmpName" runat="server" Text='<%# Bind("gender")%>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>

    </Columns>
    </asp:GridView>
    </ItemTemplate>
    </asp:TemplateField>

    </Columns>
    </asp:GridView>
    </div>
    </form>
</body>

</html>


--------------------------
ASPX.CS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Grid : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ado OuterGridBind = new ado();
        GVOuterGrid.DataSource = OuterGridBind.outerGrid();
        GVOuterGrid.DataBind();

    }
    protected void GVOuterGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
      

            ado InnerGridBind = new ado();
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //string depid="ssss";
                string DepId = GVOuterGrid.DataKeys[e.Row.RowIndex].Value.ToString();
                GridView inner = e.Row.FindControl("GVinnerGrid") as GridView;
                inner.DataSource = InnerGridBind.innerGrid(Convert.ToInt32(DepId));
                inner.DataBind();
            }
     
            Response.Write("Under Constraction");
      
    }
}


--------------------