HOW TO CREATE MENU BAR, GRID VIEW, DYNAMIC TABLE AND THREE TIER ARCHITECTURE USING ASP.NET WITH C# 3.5

Introduction:
  Here, I was developed small application about student details using three tier architecture in asp.net.
This application should teach to u regarding how to create menu bar and how to create grid view and how to create dynamic table and how to create & use of three tier architecture in asp.net with c#. Now lets go to view how to create and use the application in .net c#.

Problem:

  This application has three parts that is head part i.e., above of Grid view and Middle part contains only Grid View and Footer Part i.e., below of Grid View..

 The Problem is as follows: First entered mandatory fields details in Head Part and Footer Part after that entered Middle part that is Grid View part in that entered all fields and while click "Save/Add New" link button check whether Head Part Auto ID Generated or not . Ex. Auto ID means 'AT - 1'.
If auto ID is created then only allows to "Save / Add New" Function on Middle Part else will show error message like "Please Enter Head Part Items" or any thing...

SOLUTION:

 This Problem solves through DYNAMIC Table. The Auto ID is saved into dynamic table and check before Grid View "Save" button is clicked. Now lets go to Create and Use the above Controls are as follows:


Step 1:
 Open Visual studio 2008
step 2:
  In Default.aspx page ->select menu bar from tool box and create the Multi view bar inside of menu bar..
Inside of Multi View should contains one Grid View..These steps should cleared only understanding my basic codings..

steps 3:
  validate is client side ie., java script..
step4:
 After Creating 3 class files..1.Entity Layer 2.Logical Layer 3.Database Access Layer..

step 5: press F5

Default.aspx:
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
     <table align="center" cellpadding="0" cellspacing="0" width="100%" style="background-color:White;">
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td class="Rowstyle">
                    <table align="center" cellpadding="0" cellspacing="0" width="95%" >
                        <tr>
                            <td>
                               <asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" onmenuitemclick="Menu1_MenuItemClick">
                                   

                                  <Items>
                                    <asp:MenuItem  Text="Add Application" Value="0"></asp:MenuItem>
                                    <asp:MenuItem  Text="View Application" Value="1"></asp:MenuItem>
                                  </Items>
                                </asp:Menu>
                            </td>
                        </tr>
                        <tr>
                            <td >
                            <div >
                                    <asp:MultiView ID="MultiView1" runat="server">
                                        <asp:View runat="server" ID="View1">
                                            <table align="center" cellpadding="0" cellspacing="0" width="100%">
                                            
                                                <tr>                                                
                                                    <td>&nbsp;</td>
                                                    <td >
                                                        FIRST NAME
                                                    </td>
                                                    <td >
                                                        :
                                                    </td>
                                                    <td >
                                                        <asp:TextBox ID="txt_FN" runat="server" TabIndex="1"></asp:TextBox>
                                                    </td>
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                   
                                                    <td >
                                                        COUNTRY
                                                    </td>
                                                    <td >
                                                        :
                                                    </td>
                                                   
                                                    <td>
                                                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                                    <ContentTemplate>
                                                        <asp:DropDownList ID="ddl_Ctry" runat="server" AutoPostBack="true"
                                                            onselectedindexchanged="ddl_Ctry_SelectedIndexChanged" TabIndex="2" >
                                                        </asp:DropDownList>
                                                        </ContentTemplate>
                                                        </asp:UpdatePanel>
                                                    </td>
                                                   
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td>&nbsp;</td>
                                                    <td >
                                                        LAST NAME
                                                    </td>
                                                    <td >
                                                        :
                                                    </td>
                                                    <td >
                                                        <asp:TextBox ID="txt_LN" runat="server" MaxLength="20" TabIndex="3" ></asp:TextBox>
                                                    </td>
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                    <td >
                                                        STATE
                                                    </td>
                                                    <td >
                                                        :
                                                    </td>
                                                   
                                                    <td >
                                                    <asp:UpdatePanel ID="update2" runat="server">
                                                    <ContentTemplate>
                                                        <asp:DropDownList ID="ddl_Ste" runat="server" AutoPostBack="true"
                                                            onselectedindexchanged="ddl_Ste_SelectedIndexChanged" TabIndex="4" >
                                                           
                                                        </asp:DropDownList>
                                                        </ContentTemplate>
                                                        </asp:UpdatePanel>
                                                    </td>
                                                    
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td class="style3">
                                                    </td>
                                                    <td >
                                                        FULL NAME
                                                    </td>
                                                    <td >
                                                        :
                                                    </td>
                                                    <td >
                                                        <asp:TextBox ID="txt_FuNa" runat="server"
                                                           
                                                            TabIndex="5" ></asp:TextBox>
                                                    </td>
                                                    <td class="style3">
                                                    </td>
                                                    <td class="style3">
                                                    </td>
                                                    <td >
                                                        CITY
                                                    </td>
                                                    <td ">
                                                        :
                                                    </td>
                                                    <td >
                                                    <asp:UpdatePanel ID="update3" runat="server">
                                                    <ContentTemplate>
                                                        <asp:DropDownList ID="ddl_City" runat="server" AutoPostBack="true"
                                                            onselectedindexchanged="ddl_City_SelectedIndexChanged" TabIndex="6">
                                                        </asp:DropDownList>
                                                        </ContentTemplate>
                                                        </asp:UpdatePanel>
                                                    </td>
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                </tr>
                                                <tr><td colspan="10">&nbsp;</td></tr>
                                                <tr><td colspan="10">&nbsp;</td></tr>
                                                <tr>
                                                    <td>&nbsp;</td>
                                                    <td colspan="9" >
                                                       <asp:UpdatePanel ID="UP1" runat="server">
                                                            <ContentTemplate>
                                                                <asp:GridView ID="GridView1" runat="server" AllowPaging="True" PagerStyle-HorizontalAlign="Center"
                                                                    AllowSorting="True" AutoGenerateColumns="False" Width="100%"
                                                                    ShowFooter="True" onpageindexchanging="GridView1_PageIndexChanging"
                                                                    onrowcommand="GridView1_RowCommand" onrowdeleting="GridView1_RowDeleting"
                                                                    onrowupdating="GridView1_RowUpdating" onsorted="GridView1_Sorted"
                                                                    CellPadding="4" ForeColor="#333333" GridLines="None"
                                                                    onsorting="GridView1_Sorting" PageSize="5">
                                                                  
                                                                    <Columns>
                                                                        <asp:TemplateField HeaderText="STU_ROLL NO" >
                                                                            <FooterTemplate>
                                                                                <asp:TextBox ID="txt_sRNO" runat="server" Visible="false" ></asp:TextBox>
                                                                            </FooterTemplate>
                                                                            <ItemTemplate>
                                                                                <asp:TextBox ID="txt_sRNO" runat="server" Text='<%# Bind("sRollNo") %>' ></asp:TextBox>
                                                                            </ItemTemplate>
                                                                        </asp:TemplateField>
                                                                        <asp:TemplateField HeaderText="STU_TUTION FEES" >
                                                                            <FooterTemplate>
                                                                                <asp:TextBox ID="txt_sTF" runat="server"  Visible="false"  MaxLength="5"></asp:TextBox>
                                                                            </FooterTemplate>
                                                                            <ItemTemplate>
                                                                                <asp:TextBox ID="txt_sTF" runat="server"  Text='<%# Bind("sTuFees") %>' MaxLength="5"
                                                                                    ></asp:TextBox>
                                                                            </ItemTemplate>
                                                                        </asp:TemplateField>
                                                                        <asp:TemplateField HeaderText="STU_MESS FEES" >
                                                                            <FooterTemplate>
                                                                                <asp:TextBox ID="txt_sMF" runat="server"  Visible="false"  MaxLength="5" ></asp:TextBox>
                                                                            </FooterTemplate>
                                                                            <ItemTemplate>
                                                                                <asp:TextBox ID="txt_sMF" runat="server" Text='<%# Bind("sMeFees") %>'
                                                                                     MaxLength="5"
                                                                                    ></asp:TextBox>
                                                                            </ItemTemplate>
                                                                        </asp:TemplateField>
                                                                        <asp:TemplateField HeaderText="STU_EXTRA FEES" >
                                                                            <FooterTemplate>
                                                                                <asp:TextBox ID="txt_sEF" runat="server"  Visible="false" MaxLength="5" ></asp:TextBox>
                                                                            </FooterTemplate>
                                                                            <ItemTemplate>
                                                                                <asp:TextBox ID="txt_sEF" runat="server"  Text='<%# Bind("sExFees") %>'
                                                                                    MaxLength="5"
                                                                                    ></asp:TextBox>
                                                                            </ItemTemplate>
                                                                        </asp:TemplateField>
                                                                        <asp:TemplateField HeaderText="STU_TOTAL AMOUNT" >
                                                                            <FooterTemplate>
                                                                                <asp:TextBox ID="txt_sTA" runat="server" Visible="false" MaxLength="5" ></asp:TextBox>
                                                                            </FooterTemplate>
                                                                            <ItemTemplate>
                                                                                <asp:TextBox ID="txt_sTA" runat="server"  Text='<%# Bind("sTotAmt") %>' MaxLength="5"
                                                                                    ></asp:TextBox>
                                                                            </ItemTemplate>
                                                                        </asp:TemplateField>
                                                                        <asp:TemplateField>
                                                                            <FooterTemplate>
                                                                                <asp:LinkButton ID="lnk_AddNew1" runat="server" CommandName="btn_AddNew1">AddNew</asp:LinkButton>
                                                                                <asp:LinkButton ID="lnk_Save" runat="server" Visible="false" CommandName="btn_Save" >Save</asp:LinkButton>
                                                                                <asp:LinkButton ID="lnk_Cancel" runat="server" Visible="false" CommandName="btn_Cancel">Cancel</asp:LinkButton>
                                                                            </FooterTemplate>
                                                                            <ItemTemplate>
                                                                                <asp:LinkButton ID="lnk_Update" runat="server" CommandName="Update" >Update</asp:LinkButton>
                                                                                <asp:LinkButton ID="lnk_Delete" runat="server" CommandName="Delete">Delete</asp:LinkButton>
                                                                            </ItemTemplate>
                                                                        </asp:TemplateField>
                                                                    </Columns>
                                                                    <HeaderStyle  />
                                                                    <FooterStyle  />
                                                                    <RowStyle  />
                                                                    <AlternatingRowStyle  />
                                                                    <PagerStyle HorizontalAlign="Center" />
                                                                    <EmptyDataTemplate>
                                                                        <table cellpadding="0" cellspacing="0" width="100%">
                                                                            <tr>
                                                                                <th >
                                                                                    STU_ROLLNO
                                                                                </th>
                                                                                <th >
                                                                                    STU_TUTION FEES
                                                                                </th>
                                                                                <th >
                                                                                    STU_MESS FEES
                                                                                </th>
                                                                                <th >
                                                                                    STU_EXTRA FEES
                                                                                </th>
                                                                                <th >
                                                                                    STU_TOTAL AMOUNT
                                                                                </th>
                                                                                <th >
                                                                                </th>
                                                                            </tr>
                                                                            <tr>
                                                                                <td >
                                                                                    <asp:TextBox ID="txt_sRNO" runat="server"></asp:TextBox>
                                                                                </td>
                                                                                <td >
                                                                                    <asp:TextBox ID="txt_sTF" runat="server"
                                                                                        MaxLength="5" ></asp:TextBox>
                                                                                </td>
                                                                                <td >
                                                                                    <asp:TextBox ID="txt_sMF" runat="server"MaxLength="5"
                                                                                     ></asp:TextBox>
                                                                                </td>
                                                                                <td >
                                                                                    <asp:TextBox ID="txt_sEF" runat="server"MaxLength="5"
                                                                                       ></asp:TextBox>
                                                                                </td>
                                                                                <td >
                                                                                    <asp:TextBox ID="txt_sTA" runat="server"
                                                                                        ></asp:TextBox>
                                                                                </td>
                                                                                <td >
                                                                                    <asp:LinkButton ID="lnk_AddNew" runat="server"  CommandName="btn_AddNew" Text="AddNew" MaxLength="5" ></asp:LinkButton>                                                                 
                                                                                </td>
                                                                            </tr>
                                                                            <tfoot >
                                                                            <tr>
                                                                            <td colspan="6"></td>
                                                                            </tr>
                                                                            </tfoot>
                                                                        </table>
                                                                    </EmptyDataTemplate>
                                                                   
                                                                </asp:GridView>
                                                            </ContentTemplate>
                                                        </asp:UpdatePanel>
                                                    </td>
                                                    <td>&nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td colspan="10">&nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        &nbsp;
                                                    </td>
                                                    <td >
                                                        PHOTO</td>
                                                    <td >
                                                        :
                                                    </td>
                                                    <td >
                                                  
                                                        <asp:FileUpload ID="FileUpload1" runat="server" />
                                                          
                                                    </td>
                                                    <td>
                                                        &nbsp;
                                                    </td>
                                                    <td>
                                                        &nbsp;
                                                    </td>
                                                    <td >
                                                        JOINING DATE
                                                    </td>
                                                    <td >
                                                        :
                                                    </td>
                                                    <td >
                                                        <asp:TextBox ID="txt_Date" runat="server"
                                                            TabIndex="8"></asp:TextBox>
                                                        
 --Here use asp.net date picker..
                                                    </td>
                                                    <td>&nbsp; </td>
                                                    <td>&nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td>&nbsp;</td>
                                                    <td >
                                                        EMAIL ID
                                                    </td>
                                                    <td >
                                                        :
                                                    </td>
                                                    <td >
                                                        <asp:TextBox ID="txt_EmailId" runat="server" TabIndex="9"></asp:TextBox>
                                                    </td>
                                                    <td colspan="6">&nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td colspan="10" align="center" >
                                                   
                                                        <asp:Button ID="btn_Cancel" runat="server" Text="Cancel"  TabIndex="11" />&nbsp;&nbsp;
                                                        <asp:Button ID="btn_Save" runat="server" Text="Save" onclick="btn_Save_Click" TabIndex="10" />
                                                           
                                                    </td>
                                                </tr>
                                               
                                            </table>
                                        
                                        </asp:View>
                                        <asp:View ID="View2" runat="server">
                                            <uc1:ViewPage ID="ViewPage1" runat="server" />
                                        </asp:View>
                                    </asp:MultiView>
                            </div>
                            </td>
                        </tr>
                        <tr><td>&nbsp;</td></tr>
                    </table>
                </td>
            </tr>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td>
                    <asp:HiddenField ID="HiddenField1" runat="server" />
                </td>
            </tr>
            <tr><td>&nbsp;</td></tr>
            <tr><td>&nbsp;</td></tr>
        </table>
    </form>
 

</body>



Defualt.aspx.cs------------  Code behind File

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ETL_NewTest;
using DAL_NewTest;
using BAL_NewTest;



public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            MultiView1.ActiveViewIndex = 0;
            Entity.BindTable = Entity.CreateDynTab();
            Entity.BindTable.Clear();
            FillGirdView();           
            ddl_Ctry.Items.Add(new ListItem("--Select--", "0"));
            FillCountry();
            ddl_Ste.Items.Add(new ListItem("--Select--", "0"));
            ddl_City.Items.Add(new ListItem("--Select--", "0"));
            Menu1.Items[1].Enabled = false;
        }
    }

    private void FillCountry()
    {
        ddl_Ctry.DataSource = Logic.callCtry();
        ddl_Ctry.DataTextField = "HTC_cName";
        ddl_Ctry.DataValueField = "HTC_Id";
        ddl_Ctry.DataBind(); 
    }

    private void FillState()
    {
        Entity.callCtry = ddl_Ctry.SelectedValue.ToString();
        ddl_Ste.DataSource = Logic.callSte();
        ddl_Ste.DataTextField = "HTS_sName";
        ddl_Ste.DataValueField = "HTS_Id";
        ddl_Ste.DataBind();
    }
    private void FillCity()
    {
        Entity.callSte = ddl_Ste.SelectedValue.ToString();
        ddl_City.DataSource = Logic.callCity();
        ddl_City.DataTextField = "HTc_cName";
        ddl_City.DataValueField = "HTc_Id";
        ddl_City.DataBind();
    }
    private void FillGirdView()
    {
        GridView1.DataSource = Entity.BindTable.DefaultView;       
        GridView1.DataBind();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "btn_AddNew")
        {
            GridViewRow gvr = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
            Entity._sRNO = ((TextBox)gvr.FindControl("txt_sRNO")).Text;
            Entity._sTF = Convert.ToInt32(((TextBox)gvr.FindControl("txt_sTF")).Text);
            Entity._sMF = Convert.ToInt32(((TextBox)gvr.FindControl("txt_sMF")).Text);
            Entity._sEF = Convert.ToInt32(((TextBox)gvr.FindControl("txt_sEF")).Text);
            Entity._sTA = Convert.ToInt32(((TextBox)gvr.FindControl("txt_sTA")).Text);
            Logic.callSave();
           
            FillGirdView();
        }
        if (e.CommandName == "btn_AddNew1")
        {
           GridViewRow gvr = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
           Felds(true, gvr);
        }
        if (e.CommandName == "btn_Save")
        {
            GridViewRow gvr = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
            Entity._sRNO = ((TextBox)gvr.FindControl("txt_sRNO")).Text;
            Entity._sTF = Convert.ToInt32(((TextBox)gvr.FindControl("txt_sTF")).Text);
            Entity._sMF = Convert.ToInt32(((TextBox)gvr.FindControl("txt_sMF")).Text);
            Entity._sEF = Convert.ToInt32(((TextBox)gvr.FindControl("txt_sEF")).Text);
            Entity._sTA = Convert.ToInt32(((TextBox)gvr.FindControl("txt_sTA")).Text);
            Logic.callSave();

            FillGirdView();
            Felds(false, gvr);

        }
        if (e.CommandName == "btn_Cancel")
        {
            GridViewRow gvr = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
           
            FiledsClear(gvr);
            Felds(false, gvr);
        }
    }

    private void FiledsClear(GridViewRow gvr)
    {
        ((TextBox)gvr.FindControl("txt_sRNO")).Text = "";
        ((TextBox)gvr.FindControl("txt_sTF")).Text = "";
        ((TextBox)gvr.FindControl("txt_sMF")).Text = "";
        ((TextBox)gvr.FindControl("txt_sEF")).Text = "";
        ((TextBox)gvr.FindControl("txt_sTA")).Text = "";
      
    }

    private void Felds(Boolean vis, GridViewRow gvr)
    {
        ((TextBox)gvr.FindControl("txt_sRNO")).Visible = vis;
        ((TextBox)gvr.FindControl("txt_sTF")).Visible = vis;
        ((TextBox)gvr.FindControl("txt_sMF")).Visible = vis;
        ((TextBox)gvr.FindControl("txt_sEF")).Visible = vis;
        ((TextBox)gvr.FindControl("txt_sTA")).Visible = vis;
        if (vis == true)
        {
            ((LinkButton)gvr.FindControl("lnk_AddNew1")).Visible = false;
            ((LinkButton)gvr.FindControl("lnk_Save")).Visible = true;
            ((LinkButton)gvr.FindControl("lnk_Cancel")).Visible = true;
        }
        else
        {
            ((LinkButton)gvr.FindControl("lnk_AddNew1")).Visible = true;

            ((LinkButton)gvr.FindControl("lnk_Save")).Visible = false;
            ((LinkButton)gvr.FindControl("lnk_Cancel")).Visible = false;
        }

    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Entity._RowIndex = Convert.ToInt32(e.RowIndex.ToString());
        Entity._sRNO = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txt_sRNO")).Text;
        Entity._sTF = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].FindControl("txt_sTF")).Text);
        Entity._sMF = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].FindControl("txt_sMF")).Text);
        Entity._sEF = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].FindControl("txt_sEF")).Text);
        Entity._sTA = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].FindControl("txt_sTA")).Text);
        Logic.callUpdate();
        FillGirdView();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        FillGirdView();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Entity.BindTable.Rows[Entity._RowIndex].Delete();
        FillGirdView();
    }
    protected void GridView1_Sorted(object sender, EventArgs e)
    {

    }
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        Entity._sFN = txt_FN.Text;
        Entity._sLn = txt_LN.Text;
        Entity._sFuN = txt_FuNa.Text;
        Entity._sCtry = ddl_Ctry.SelectedItem.ToString();
        Entity._sSte = ddl_Ste.SelectedItem.ToString();
        Entity._sCity = ddl_City.SelectedItem.ToString();
//        Entity._sPhoto = FileUpload1.FileName;

        if(FileUpload1.HasFile)
        {
            string[] getImageName = FileUpload1.FileName.Split('.');
            string ImgName = FileUpload1.FileName + "," + DateTime.Now.ToFileTime() + "." + getImageName[1];
            Entity._sPhoto = ImgName;
            if (getImageName[1] == "jpg" || getImageName[1] == "jpeg" || getImageName[1] == "bmp")
            {
                string savePath = HttpContext.Current.Server.MapPath("Upload/" + Entity._sPhoto);
                FileUpload1.SaveAs(savePath);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", "alert('Please Upload [.jpg/.jpeg/.bmp] files only');", true);
            }
        }

        Entity._sEmaId = txt_EmailId.Text;
        Entity._sJDate= txt_Date.Text;
       
        Boolean val = Logic.callAllSave();

        if (val)
        {
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", "alert('Head Items Saved Successfully');", true);
            Boolean val1 = Logic.callGridSave();
            if (val1)
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert1", "alert('Grid Items Saved Successfully');", true);
               // Menu1.SelectedItem.Text = "View Application";
               //Entity.BindTable = Entity.CreateDynTab();
               //Entity.BindTable.Clear();
               //FillGirdView();
               //MultiView1.ActiveViewIndex = 1;
                Menu1.Items[1].Enabled = true;
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert1", "alert('Failed Grid Items Saved');", true);
            }
                   
        }
        else
        {
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert2", "alert('Failed Save Head Items');", true);
        }
    }
    protected void ddl_Ctry_SelectedIndexChanged(object sender, EventArgs e)
    {       
        FillState();
    }

   
    protected void ddl_City_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void ddl_Ste_SelectedIndexChanged(object sender, EventArgs e)
    {
        FillCity();
    }


    protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
    {
        MultiView1.ActiveViewIndex = Int32.Parse(Menu1.SelectedValue);
        switch (e.Item.Text)
        {
            case "Add Application":
                MultiView1.ActiveViewIndex = 0;
                Response.Redirect("Default.aspx");
                break;
            case "View Application":
                MultiView1.ActiveViewIndex = 1;
               
                break;

        }
    }

  
    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        if (ViewState["sortOrder"].ToString() == "desc")
        {
            ViewState["sortOrder"] = "asc";
       }
        else
        {
            ViewState["sortOrder"] = "desc";

        }
       HiddenField1.Value = e.SortExpression;
       FillGirdView();
    }





Entity Layer Access.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ETL_NewTest
{
    public class Entity
    {
        public static DataTable CreateDynTab()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("sRollNo", typeof(string));
            dt.Columns.Add("sTuFees", typeof(int));
            dt.Columns.Add("sMeFees", typeof(int));
            dt.Columns.Add("sExFees", typeof(int));
            dt.Columns.Add("sTotAmt", typeof(int));
            return dt;
        }

        public static DataTable BindTable{get;set;}

        public static string _sFN { get; set; }
        public static string _sLn { get; set; }
        public static string _sFuN { get; set; }
        public static string _sCtry { get; set; }
        public static string _sSte { get; set; }
        public static string _sCity { get; set; }
        public static string _sPhoto { get; set; }
        public static string _sEmaId { get; set; }
        public static string _sJDate { get; set; }

        public static string _sRNO { get; set; }
        public static int _sTF { get; set; }
        public static int _sMF { get; set; }
        public static int _sEF { get; set; }
        public static int _sTA { get; set; }


        public static int _RowIndex { get; set; }

       


        public static string callCtry { get; set; }
        public static string callSte { get; set; }
        public static string callCity { get; set; }
        public static string getAutoId { get; set; }
        public static string getSearchText { get; set; }       
     }
}
Logical Layer.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAL_NewTest;


namespace BAL_NewTest
{
    public class Logic
    {

        public static DataTable callSave()
        {
            return BackEnd.SaveDynTab();
        }
        public static DataTable callUpdate()
        {
            return BackEnd.UpdateDynTab();
        }

      

        public static Boolean callGridSave()
        {
            return BackEnd.GridSave();
        }
        public static Boolean callAllSave()
        {
            return BackEnd.AllSave();
        }

        public static DataTable callCtry()
        {
            return BackEnd.Country();
        }

        public static DataTable callSte()
        {
            return BackEnd.State();
        }

        public static DataTable callCity()
        {
            return BackEnd.City();
        }

        public static DataTable callBindGV()
        {
            return BackEnd.BindViewPage_GV();
        }

        public static DataTable callBindSearchGV()
        {           
            return BackEnd.BindSearchPage_GV();
        }

       

    }
}


DataBase Access Layer.cs

using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ETL_NewTest;
using System.Data;
using System.Data.SqlClient;

namespace DAL_NewTest
{
    public class BackEnd
    {

        public static DataTable SaveDynTab()
        {
           
            DataRow dr;
            dr = Entity.BindTable.NewRow();
            dr["sRollNo"] = Entity._sRNO;
            dr["sTuFees"] = Entity._sTF;
            dr["sMeFees"] = Entity._sMF;
            dr["sExFees"] = Entity._sEF;
            dr["sTotAmt"] = Entity._sTA;
            Entity.BindTable.Rows.Add(dr);

            return Entity.BindTable;


        }

        public static DataTable UpdateDynTab()
        {
            Entity.BindTable.Rows[Entity._RowIndex].BeginEdit();
            Entity.BindTable.Rows[Entity._RowIndex]["sRollNo"]=Entity._sRNO;
            Entity.BindTable.Rows[Entity._RowIndex]["sTuFees"]=Entity._sTF;
            Entity.BindTable.Rows[Entity._RowIndex]["sMeFees"]=Entity._sMF;
            Entity.BindTable.Rows[Entity._RowIndex]["sExFees"]=Entity._sEF;
            Entity.BindTable.Rows[Entity._RowIndex]["sTotAmt"] = Entity._sTA;
            Entity.BindTable.Rows[Entity._RowIndex].AcceptChanges();
            return Entity.BindTable;
        }

      


        public static Boolean GridSave()
        {
            //if (string.IsNullOrEmpty(Entity._sRNO) || string.IsNullOrEmpty(Convert.ToString((Entity._sTF)))
            //    || string.IsNullOrEmpty(Convert.ToString((Entity._sMF))) || string.IsNullOrEmpty(Convert.ToString((Entity._sEF))) || string.IsNullOrEmpty(Convert.ToString((Entity._sTA))))
            //{
            //    return false;
            //}
            //else
            //{

                string conStr = ConfigurationManager.ConnectionStrings["myConStr"].ConnectionString;
                SqlConnection con;
                SqlCommand cmd;
                //SqlDataAdapter sqlda;
               // DataTable dt;

                foreach (DataRow dr in Entity.BindTable.Rows)
                {
                    using (con = new SqlConnection(conStr))
                    {
                        con.Open();
                        using (cmd = new SqlCommand("SP_StuForm_GridTab_Save", con))
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.AddWithValue("@GT_sRollNo", dr["sRollNo"].ToString());
                            cmd.Parameters.AddWithValue("@GT_sTuFees", dr["sTuFees"].ToString());
                            cmd.Parameters.AddWithValue("@GT_sMeFees", dr["sMeFees"].ToString());
                            cmd.Parameters.AddWithValue("@GT_sExFees", dr["sExFees"].ToString());
                            cmd.Parameters.AddWithValue("@GT_sTotAmt", dr["sTotAmt"].ToString());
                            cmd.ExecuteNonQuery();
                        }
                    }
                }

                return true;
            //}
           
        }

        public static Boolean AllSave()
        {
                string conStr = ConfigurationManager.ConnectionStrings["myConStr"].ConnectionString;
                SqlConnection con;
                SqlCommand cmd;
                //SqlDataAdapter sqlda;
                //DataTable dt;
                using (con = new SqlConnection(conStr))
                {
                    con.Open();
                    using (cmd = new SqlCommand("SP_StuForm_MainTab_SaveAll", con))
                    {                       
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@MT_sFirstName", Entity._sFN);
                        cmd.Parameters.AddWithValue("@MT_sLastName", Entity._sLn);
                        cmd.Parameters.AddWithValue("@MT_sFullName", Entity._sFuN);
                        cmd.Parameters.AddWithValue("@MT_sCountry", Entity._sCtry);
                        cmd.Parameters.AddWithValue("@MT_sState", Entity._sSte);
                        cmd.Parameters.AddWithValue("@MT_sCity", Entity._sCity);
                        cmd.Parameters.AddWithValue("@MT_sPhoto", Entity._sPhoto);
                        cmd.Parameters.AddWithValue("@MT_sEmailId", Entity._sEmaId);
                        cmd.Parameters.AddWithValue("@MT_sJoinDate", Entity._sJDate);                          
                       
                        cmd.ExecuteNonQuery();
                        return true;
                    }
                }
        }

        public static Boolean Delete()
        {
            return true;
        }

        public static DataTable Country()
        {
             string conStr = ConfigurationManager.ConnectionStrings["myConStr"].ConnectionString;
            SqlConnection con;
            //SqlCommand cmd;
            SqlDataAdapter sqlda;
            DataTable dt;
            using (con = new SqlConnection(conStr))
            {
                con.Open();
                string CtryQry = "select * from HT_Country  ";
                using (sqlda = new SqlDataAdapter(CtryQry, con))
                {
                    dt = new DataTable();
                    sqlda.Fill(dt);
                }
            }
            return dt;
        }

        public static DataTable State()
        {
            string conStr = ConfigurationManager.ConnectionStrings["myConStr"].ConnectionString;
            SqlConnection con;
            //SqlCommand cmd;
            SqlDataAdapter sqlda;
            DataTable dt;
            using (con = new SqlConnection(conStr))
            {
                con.Open();
                string SteQry = "select * from HTC_State where HTCS_Id='" + Entity.callCtry + "' ";
                using (sqlda = new SqlDataAdapter(SteQry, con))
                {
                    dt = new DataTable();
                    sqlda.Fill(dt);
                }
            }
            return dt;
        }


        public static DataTable City()
        {
            string conStr = ConfigurationManager.ConnectionStrings["myConStr"].ConnectionString;
            SqlConnection con;
            //SqlCommand cmd;
            SqlDataAdapter sqlda;
            DataTable dt;
            using (con = new SqlConnection(conStr))
            {
                con.Open();
                string CityQry = "select * from HTS_City where HTSc_Id='" + Entity.callSte + "' ";
                using (sqlda = new SqlDataAdapter(CityQry, con))
                {
                    dt = new DataTable();
                    sqlda.Fill(dt);
                }
            }
            return dt;
        }

        public static DataTable BindViewPage_GV()
        {
            string conStr = ConfigurationManager.ConnectionStrings["myConStr"].ConnectionString;
            SqlConnection con;
            SqlCommand cmd;
            SqlDataAdapter sqlda;
            DataTable dt;
            using (con = new SqlConnection(conStr))
            {
                con.Open();
                //string selQry = "select top 1 MT_AGId from HeadTab order by MT_AGId desc";
                string selQryy = "select 'STU - '+CONVERT(varchar(20), value) from AutoGen";
                using (cmd = new SqlCommand(selQryy, con))
                {
                    dt = new DataTable();
                    sqlda = new SqlDataAdapter(cmd);
                    sqlda.Fill(dt);


                    foreach (DataRow dr in dt.Rows)
                    {
                        Entity.getAutoId = dr[0].ToString();
                    }
                    //int no = Convert.ToInt32(cmd.ExecuteScalar());
                    //Entity.getAutoId = Convert.ToString(no);
                }
            }

            using (con = new SqlConnection(conStr))
            {
                con.Open();
                string CityQry = @"select MT_sFirstName,MT_sLastName,MT_sFullName,MT_sCountry,MT_sState,MT_sCity,MT_sPhoto,MT_sEmailId,
                                   MT_sJoinDate,MT_AGId,GT_sRollNo,GT_sTuFees,GT_sMeFees,GT_sExFees,GT_sTotAmt,GT_mAGId
                                   from HeadTab inner join GridTab1 on GT_mAGId=MT_AGId where MT_AGId='" + Entity.getAutoId + "' ";

                using (sqlda = new SqlDataAdapter(CityQry, con))
                {
                    dt = new DataTable();
                    sqlda.Fill(dt);
                    foreach (DataRow dr in dt.Rows)
                    {
                        Entity._sFN = dr["MT_sFirstName"].ToString();
                        Entity._sLn = dr["MT_sLastName"].ToString();
                        Entity._sFuN = dr["MT_sFullName"].ToString();
                        Entity._sCtry = dr["MT_sCountry"].ToString();
                        Entity._sSte = dr["MT_sState"].ToString();
                        Entity._sCity = dr["MT_sCity"].ToString();
                        Entity._sPhoto = dr["MT_sPhoto"].ToString();
                        Entity._sJDate = dr["MT_sJoinDate"].ToString();
                        Entity._sEmaId = dr["MT_sEmailId"].ToString();

                    }
                }
            }



            return dt;
        }

       
        public static DataTable BindSearchPage_GV()
        {
            string conStr = ConfigurationManager.ConnectionStrings["myConStr"].ConnectionString;
            SqlConnection con;
            //SqlCommand cmd;
            SqlDataAdapter sqlda;
            DataTable dt;
           
            using (con = new SqlConnection(conStr))
            {
                con.Open();
                string CityQry = @"select MT_sFirstName,MT_sLastName,MT_sFullName,MT_sCountry,MT_sState,MT_sCity,MT_sPhoto,MT_sEmailId,
                                   MT_sJoinDate,MT_AGId,GT_sRollNo,GT_sTuFees,GT_sMeFees,GT_sExFees,GT_sTotAmt,GT_mAGId
                                   from HeadTab inner join GridTab1 on GT_mAGId=MT_AGId where MT_AGId='" + Entity.getSearchText + "' ";

                using (sqlda = new SqlDataAdapter(CityQry, con))
                {
                    dt = new DataTable();
                    sqlda.Fill(dt);
                    foreach (DataRow dr in dt.Rows)
                    {
                        Entity._sFN = dr["MT_sFirstName"].ToString();
                        Entity._sLn = dr["MT_sLastName"].ToString();
                        Entity._sFuN = dr["MT_sFullName"].ToString();
                        Entity._sCtry = dr["MT_sCountry"].ToString();
                        Entity._sSte = dr["MT_sState"].ToString();
                        Entity._sCity = dr["MT_sCity"].ToString();
                        Entity._sPhoto = dr["MT_sPhoto"].ToString();
                        Entity._sJDate = dr["MT_sJoinDate"].ToString();
                        Entity._sEmaId = dr["MT_sEmailId"].ToString();

                    }
                }
            }



            return dt;
        }



       


    }
}


ViewPage.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ETL_NewTest;
using BAL_NewTest;
using DAL_NewTest;

public partial class NewTest_ViewPage : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ViewState["sortOrder"] = "";
        FillGridView();
        lbl_FN.Text = Entity._sFN;
        lbl_LN.Text = Entity._sLn;
        lbl_FuN.Text = Entity._sFuN;
        lbl_Country.Text = Entity._sCtry;
        lbl_State.Text = Entity._sSte;
        lbl_City.Text = Entity._sCity;
        lbl_EmailId.Text = Entity._sEmaId;
        lbl_JoDate.Text = Entity._sJDate;
       
            string[] dispFileName = Entity._sPhoto.Split(',');
            lnk_Photo.Text = dispFileName[0];

            txt_Search.Text = "";
              
         
       
    }

    private void FillGridView()
    {
        if (!string.IsNullOrEmpty(txt_Search.Text) && !string.IsNullOrEmpty(Entity.getAutoId))
        {
            Entity.getSearchText = txt_Search.Text;
            DataView dv1 = new DataView();
            dv1 = Logic.callBindSearchGV().DefaultView;
            GridView1.DataSource = dv1;
            if (!string.IsNullOrEmpty(Convert.ToString(ViewState["sortOrder"])) && !string.IsNullOrEmpty(HiddenField1.Value))
            {
                dv1.Sort = string.Format("{0} {1}", HiddenField1.Value, Convert.ToString(ViewState["sortOrder"]));

            }
            GridView1.DataBind();
        }

        else if (string.IsNullOrEmpty(txt_Search.Text) || !string.IsNullOrEmpty(Entity.getAutoId))
        {
            DataView dv = new DataView();
            dv = Logic.callBindGV().DefaultView;
            GridView1.DataSource = dv;
            if (!string.IsNullOrEmpty(Convert.ToString(ViewState["sortOrder"])) && !string.IsNullOrEmpty(HiddenField1.Value))
            {
                dv.Sort = string.Format("{0} {1}", HiddenField1.Value, Convert.ToString(ViewState["sortOrder"]));

            }
            GridView1.DataBind();
        }

       
         
      
    }
    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        if (ViewState["sortOrder"].ToString() == "desc")
        {
            ViewState["sortOrder"] = "asc";
        }
        else
        {
            ViewState["sortOrder"] = "desc";
        }
        HiddenField1.Value = e.SortExpression;
        FillGridView();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        FillGridView();
    }
    protected void lnk_Photo_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterStartupScript(this, typeof(string), "function", "window.open('PopUp.aspx','','width=300,scrollbars=1 menubar=no, height=300,resizable=yes,directories=no,location=no');", true);
    }
  
}

Comments