Showing posts with label JQuery. Show all posts
Showing posts with label JQuery. Show all posts

Sunday, November 16, 2014

MVC Model Sample with LIST,ADD,EDIT,VIEW,DELETE

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using BusinessLogic;
using BusinessObject;
using BusinessObject.Common;
using ERP.Utilities;
using ERPService;

namespace ERPHotel.Models
{
    public class UserLevelModel
    {
        #region Properties

        /// <summary>
        /// Current PK
        /// </summary>
        private int USERLEVELPK
        {
            get;
            set;
        }

        /// <summary>
        /// To maintain the PageIndex in viewstate
        /// </summary>
        private string PageIndex
        {
            get;
            set;
        }
        /// <summary>
        /// To maintain the total pages in viewstate
        /// </summary>
        private int TotalPages
        {
            get;
            set;
        }
        /// <summary>
        /// To maintain the SortExpression or sort By in viewstate
        /// </summary>
        private string SortBy
        {
            get;
            set;
        }

        /// <summary>
        /// To maintain the SortExpression or then By in viewstate
        /// </summary>
        private string ThenBy
        {
            get;
            set;
        }

        /// <summary>
        /// To maintain the Sort Direction in viewstate
        /// </summary>
        private string SortDirection
        {
            get;
            set;
        }
        /// <summary>
        /// To maintain the LastModifiedTime in viewstate
        /// </summary>
        private DateTime LastModifiedTime
        {
            get;
            set;
        }

        /// <summary>
        /// Entry State for managing display status
        /// </summary>
        private EntryStatus EntryStatus
        {
            get;
            set;
        }

        /// <summary>
        /// Page Size
        /// </summary>
        private int PageSize
        {
            get;
            set;
        }


        #endregion     
        [DisplayName("Id")]
        public int ugrp_id { get; set; }
        [DisplayName("Description :")]
        public string ugrp_name { get; set; }
        [DisplayName("Description :")]
        public string ugrp_descr { get; set; }
        [DisplayName("Designation :")]
        public string ugrp_desc { get; set; }
        [DisplayName("Is Admin Group :")]
        public bool ugrp_admin { get; set; }
        [DisplayName("User Management >> User Level")]
        public bool Breadcrumb { get; set; }

        private ServiceUtility serviceUtilityObj;
        private static user_groups user_groupsObj;
        private DataSet dsuser_groups;
        private DataTable dtuser_groups;
     

        #region Get Field Values
        /// <summary>
        /// Gets the data to bind/assign for the controls(inputs, grids, dropdowns etc.)
        /// pass string.empty to get all field values
        /// Assign it to the page level variables
        /// </summary>
        public object GetFieldValues(ControlsEnum type)
        {


            try
            {
                Object retObject;
                retObject = null;
                PageSize = 20;
                switch (type)
                {
                    case ControlsEnum.USERLEVEL:
                        user_groupsObj = new user_groups();
                        user_groupsObj.ugrp_id = USERLEVELPK;
                        serviceUtilityObj = new ServiceUtility();
                        serviceUtilityObj.CurrentPage = PageIndex == null ? 1 : Convert.ToInt32(PageIndex);
                        serviceUtilityObj.PageSize = PageSize;
                        serviceUtilityObj.SortBy = SortBy = SortBy == null ? Resources.DataFieldRes.USERLEVELPK : SortBy;
                        serviceUtilityObj.ThenBy = ThenBy = ThenBy == null ? Resources.DataFieldRes.USERLEVELPK : ThenBy;
                        serviceUtilityObj.SortDirection = SortDirection = SortDirection == null ? Resources.Report.SortDescending : SortDirection;
                        dsuser_groups = user_groupsBL.Getuser_groupsList(user_groupsObj, serviceUtilityObj);

                      
                        retObject = dsuser_groups;

                        serviceUtilityObj.TotalRecords = int.Parse(dsuser_groups.Tables[0].Rows[0][0].ToString());
                        TotalPages = serviceUtilityObj.TotalRecords == 0 ? 1 : (serviceUtilityObj.TotalRecords <= serviceUtilityObj.PageSize) ? 1 :
                                    (serviceUtilityObj.TotalRecords % serviceUtilityObj.PageSize) == 0 ? (serviceUtilityObj.TotalRecords / serviceUtilityObj.PageSize) :
                                    (serviceUtilityObj.TotalRecords / serviceUtilityObj.PageSize) + 1;

                        break;
                    case ControlsEnum.USERLEVELDETAILS:
                        dtuser_groups = user_groupsBL.Getuser_groups(USERLEVELPK);
                        if (dtuser_groups.Rows.Count > 0)
                        {
                            user_groupsObj = new user_groups();
                            user_groupsObj.ugrp_id = Convert.ToInt32(dtuser_groups.Rows[0][user_groups.F_ugrp_id].ToString());
                            user_groupsObj.ugrp_name = dtuser_groups.Rows[0][user_groups.F_ugrp_name].ToString();
                            user_groupsObj.ugrp_desc = dtuser_groups.Rows[0][user_groups.F_ugrp_desc].ToString();
                            user_groupsObj.ugrp_admin = Convert.ToBoolean(dtuser_groups.Rows[0][user_groups.F_ugrp_admin]);                          
                        }
                        retObject = user_groupsObj;
                        break;
                    case ControlsEnum.USERLEVELSEARCH:
                        user_groupsObj = new user_groups();
                        dtuser_groups = user_groupsBL.Getuser_groups(USERLEVELPK);
                        retObject = dtuser_groups;
                        break;


                }
                return retObject;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

            }
        }
        #endregion

        #region Enum
        /// <summary>
        ///Page Controls Enum
        /// </summary>
        public enum ControlsEnum
        {

            USERLEVEL,
            USERLEVELLIST,
            USERLEVELDETAILS,
            USERLEVELSEARCH
        }
     
        #endregion
    }
}

MVC Controller Sample with LIST,ADD,EDIT,VIEW,DELETE

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
using BusinessLogic;
using BusinessObject;
using ERPHotel.Models;

namespace ERPHotel.Controllers
{
    public class UserLevelController : Controller
    {
        private ActionsEnum commonActions;

        //
        // GET: /UserLevel/

        public ActionResult UserLevel(UserLevelModel model)
        {
          
            DataSet ds =(DataSet)model.GetFieldValues(UserLevelModel.ControlsEnum.USERLEVEL);           
            ViewBag.UserLevelList = ds.Tables[1];
            ViewBag.message = @"<script type='text/javascript' language='javascript'>$(document).ready(function(){ShowListing(1);});</script>";
            return View();
        }

        [HttpPost]
        public ActionResult UserLevel(ERPHotel.Models.UserLevelModel model, string Command, FormCollection frmCollection)
        {

            var radio = frmCollection.GetValue("SelectOne");

            int result = 0;
            user_groups objuser_groups = new user_groups();

            commonActions = (ActionsEnum)(Enum.Parse(typeof(ActionsEnum), Command));

            switch (commonActions)
            {
                case ActionsEnum.NEW:
                    break;
                case ActionsEnum.SAVE:
                    if (model != null)
                    {
                        objuser_groups.ugrp_admin = model.ugrp_admin;
                        objuser_groups.ugrp_desc = model.ugrp_desc;
                        objuser_groups.ugrp_id = model.ugrp_id;
                        objuser_groups.ugrp_name = model.ugrp_descr;

                        result = user_groupsBL.Saveuser_groups(objuser_groups, 1);
                        if (result > 0)
                        {
                            DataSet ds = (DataSet)model.GetFieldValues(UserLevelModel.ControlsEnum.USERLEVEL);
                            ViewBag.UserLevelList = ds.Tables[1];
                           
                        }
                    }
                    break;
                case ActionsEnum.DELETE:
                    break;
                case ActionsEnum.CANCEL:
                    break;
                case ActionsEnum.VIEW:
                    break;
                case ActionsEnum.EDIT:
                    if (model != null)
                    {
                       DataTable dtuser_groups = user_groupsBL.Getuser_groups(Convert.ToInt32(radio.AttemptedValue));
                        if (dtuser_groups.Rows.Count > 0)
                        {
                            objuser_groups = new user_groups();
                            objuser_groups.ugrp_id =Convert.ToInt32(dtuser_groups.Rows[0][user_groups.F_ugrp_id].ToString());
                            objuser_groups.ugrp_name = dtuser_groups.Rows[0][user_groups.F_ugrp_name].ToString();
                            objuser_groups.ugrp_desc = dtuser_groups.Rows[0][user_groups.F_ugrp_desc].ToString();
                            objuser_groups.ugrp_admin = Convert.ToBoolean(dtuser_groups.Rows[0][user_groups.F_ugrp_admin]);
                                                       model.ugrp_admin = objuser_groups.ugrp_admin;
                            model.ugrp_desc = objuser_groups.ugrp_desc;
                            model.ugrp_id = objuser_groups.ugrp_id;
                            model.ugrp_descr = objuser_groups.ugrp_name;
                            var ugrp_descr = frmCollection.GetValue("ugrp_descr");
                                               }
                        ViewBag.message = @"<script type='text/javascript' language='javascript'>$(document).ready(function(){ShowListing();});</script>";
                    }
                    break;
            }

            return View(model);
        }

    }
}

MVC Razor Html Design Structure Sample with LIST,ADD,EDIT,VIEW,DELETE

@model ERPHotel.Models.UserLevelModel
@{
    ViewBag.Title = "UserLevel";
    Layout = "~/Views/Home/SiteMaster.cshtml";
}

<html>

<head>
    <meta name="viewport" content="width=device-width" />
    <title>User Level</title>
    @section Scripts
{
    @Html.Raw(ViewBag.message)
}

    <script type="text/javascript">

        var pageURL = window.document.URL;
        var virtualPath = "";@* @System.Configuration.ConfigurationManager.AppSettings["VirtualDirectory"].ToString();*@
        var url = pageURL.replace(location.pathname, virtualPath == "" ? "/Handlers/AutoComplete.ashx" : "/" + virtualPath + "Handlers/AutoComplete.ashx");

        $(document).ready(function () {
           
            InitComponents();          
            ShowHideAdvancedSearch();
        });

        function InitComponents() {
            ERPScriptUtils.MakeAutoCompleteDDL("txtuserlevel", url, "hdfuserlevel", true, true, "USERLEVELAUTO");
        }

        function ShowHideAdvancedSearch(flag) {
            //If flag then Show AdvancedSearch
            if (flag) {
                $("[id$=tbladvancedSearch]").show();
                $("[id$=imbShowFilter]").hide();
                $("[id$=imbHideFilter]").show();
            }
            else {
                $("[id$=tbladvancedSearch]").hide();
                $("[id$=imbShowFilter]").show();
                $("[id$=imbHideFilter]").hide();
            }
            return false;
        }

        function ShowListing(flag) {
            alert(flag);
            if (flag) {

                $("[id$=PageAction_List]").show();
                $("[id$=PageAction_Entry]").hide();
                $("[id$=pnlListing]").show();
                $("[id$=pnlEntry]").hide();
                $("[id$=ModifiedDatePnl]").hide();
            }
            else {

                $("[id$=PageAction_List]").hide();
                $("[id$=PageAction_Entry]").show();
                $("[id$=pnlListing]").hide();
                $("[id$=pnlEntry]").show();
            }
            return false;
        }
        function ValidateNow() {
            if (typeof (Page_ClientValidate) == 'function') {
                Page_ClientValidate();
            }
            if (!Page_IsValid) {
                $("[id$=litErrorMsg]").hide();
                ShowErrorMessage($("#diverror").html());
                return false;  //Page is invalid -- stop right here
            }
            else {
                //everythings ok --- Call your function & do your stuff
                return true;
            }
        }

        function ViewMode(mode) {
            //Mode = 1 Indicates its on View Mode
            //Mode = 2 Indicates its on New Mode
            if (mode == 1) {
                $("[id$=pnlSave]").hide();
                $("[id$=pnlDelete]").hide();
            }
            else if (mode == 2) {
                $("[id$=pnlDelete]").hide();
            }
        }
        function radioselect(_this) {         
            $("[id$=hdfid]").val("1");
            //$("[id$=btnEdit]").click();
            //ShowListing();
        }


    </script>
</head>

<body>
    @using (Html.BeginForm("UserLevel", "UserLevel", FormMethod.Post))
    {
        <div class="fixed-buttons">
            <div class="button_container">
                <table>
                    <tr>
                        @*SEC_ACTION is a dummy cssclass  FOR Accessing the Buttons in the Table Cell*@
                        <td id="SEC_ActionPanel" class="SEC_ACTION">
                            <ul class="bredcrum">
                                @Html.LabelFor(m => m.Breadcrumb)

                            </ul>
                            <ul id="pnlEntry" style="display: none">
                                <li runat="server" id="pnlSave">
                                    <input type="submit" name="Command" title="@Resources.Controls.Save" 
                                        value="@Resources.Controls.Save"  class="bttn_save" id ="btnSave" />
                                </li>
                                <li runat="server" id="pnlDelete">
                                    <input type="submit" name="Command" title="@Resources.Controls.Delete" 
                                        value="@Resources.Controls.Delete" onclick="ValidateNow()" class="bttn_delete" id ="btnDelete" />
                                </li>
                                <li>
                                    <input type="submit" name="Command" title="@Resources.Controls.Cancel" 
                                        value="@Resources.Controls.Cancel" onclick="ValidateNow()" class="bttn_cancel" id ="btnCancel" />
                                </li>
                            </ul>
                            <ul id="pnlListing" style="display: none">
                                <li>
                                    <input type="button" name="Command" title="@Resources.Controls.New" 
                                        value="@Resources.Controls.New" onclick="ShowListing()" class="bttn_new" id ="btnNew" />
                                </li>
                                <li>
                                    <input type="submit"  name="Command"  title="@Resources.Controls.Edit" 
                                        value="@Resources.Controls.Edit"  class="bttn_edit" id ="btnEdit" />
                                </li>
                                <li>
                                    <input type="submit" name="Command" title="@Resources.Controls.View" 
                                        value="@Resources.Controls.View" onclick="ValidateNow()" class="bttn_view" id ="btnView" />
                                </li>

                            </ul>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div id="horizontalTab">
            <ul class="resp-tabs-list">
                <li runat="server" id="lilist" class="resp-tab-active">
                    <a id="lnkList" tabindex="33" class="tab-active" href="javascript:__doPostBack(lnkList)"
                        style="font-family: Verdana; text-decoration: none;">@Resources.PageNameRes.List</a>
                </li>
                <li runat="server" id="lidetail">
                    <a id="lnkDetail" tabindex="33" class="tab-inactive" href="javascript:__doPostBack(lnkDetail)"
                        style="font-family: Verdana; text-decoration: none;">@Resources.PageNameRes.Detail</a>
                </li>
            </ul>

            <table id="tblTemplate" class="asptbllinks">
                <tr>
                    <td>
                        <table id="PageAction_List">
                            <tr>
                                <td>
                                    <div class="search-colapse">
                                        <table>
                                            <tr>
                                                <td>
                                                    <h1>@Resources.Controls.AdvanceSearch</h1>
                                                </td>
                                                <td>
                                                    <input type="image" name="imbShowFilter" id="imbShowFilter" tabindex="65"
                                                        title="Show Filter" src="~/Content/images/Classic/Icons/arrow-colapse-inactive.png"
                                                        onclick="javascript: return ShowHideAdvancedSearch(1);"
                                                        style="border-width: 0px;" />
                                                    <input type="image" name="imbHideFilter" id="imbHideFilter" tabindex="66"
                                                        title="Hide Filter" src="~/Content/images/Classic/Icons/arrow-colapse-active.png"
                                                        onclick="javascript: return ShowHideAdvancedSearch();"
                                                        style="border-width: 0px;" />
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                    @*colpase btn*@
                                    <div class="clear">
                                    </div>
                                    <table class="table-devide advance-search" id="tbladvancedSearch" style="margin-top: 8px;">
                                        <tr id="Tr1">
                                            <td>
                                                <div class="div2col-S">
                                                    @Html.LabelFor(m => m.ugrp_name)
                                                    @Html.TextBoxFor(m => m.ugrp_name, new { id = "txtuserlevel" })
                                                    @Html.HiddenFor(m => m.ugrp_id, new { id = "hdfuserlevel" })
                                                    <div class="clear">
                                                    </div>
                                                </div>
                                            </td>
                                            <td>
                                                <div class="div2col-S">
                                                    <input type="submit" name="SEARCH" title="@Resources.Controls.Search" 
                                        value="@Resources.Controls.Search"  class="bttn_search" id ="btnSearch" />
                                                    <input type="submit" name="CLEAR" title="@Resources.Controls.Clear" 
                                        value="@Resources.Controls.Clear"  class="bttn_cancel" id ="btnClear" />

                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                    <div class="clear">
                                    </div>
                                    <div class="gridwrap">
                                        <table class="gridwrap" cellspacing="0" cellpadding="0" border="1" style="border-color: #D0D7E9; border-width: 1px; border-style: Solid; height: 10px; width: 100%; border-collapse: collapse;"
                                            id="grdUserLevel" rules="rows">
                                            <tbody>
                                                <tr class="grdhead" align="left" style="color: #506C92; border-width: 0px; font-family: Verdana; font-size: 10px; height: 25px;">
                                                    <th scope="col">&nbsp;
                                                    </th>
                                                    <th scope="col">
                                                        <a href="javascript:__doPostBack()" style="color: #506C92;">User Level</a>
                                                    </th>
                                                    <th scope="col">
                                                        <a href="javascript:__doPostBack()" style="color: #506C92;">Description</a>
                                                    </th>
                                                </tr>
                                                @if (ViewBag.UserLevelList!=null)
                                                {
                                                    foreach (System.Data.DataRow dr in ViewBag.UserLevelList.Rows)
                                                    {
                                                        <tr style="color: #263D62; background-color: White; border-color: #D0D7E9; border-width: 1px; border-style: Solid; font-family: Verdana; font-size: 11px; height: 10px;">
                                                            <td>
                                                                <input type="radio" name="SelectOne"                                                               
                                                                    id="@dr[@Resources.DataFieldRes.USERLEVELPK].ToString()"
                                                                    value="@dr[@Resources.DataFieldRes.USERLEVELPK].ToString()"
                                                                    onclick ="radioselect(@dr[Resources.DataFieldRes.USERLEVELPK].ToString())"
                                                                    />
                                                            </td>
                                                            <td>
                                                                @dr[@Resources.DataFieldRes.USERLEVEL].ToString()
                                                            </td>
                                                            <td>
                                                                @dr[@Resources.DataFieldRes.USERLEVELDESC].ToString()
                                                            </td>
                                                        </tr>
                                                    }
                                                }
                                            </tbody>
                                        </table>

                                    </div>
                                </td>
                            </tr>
                        </table>
                        <table id="PageAction_Entry">
                            <tr>
                                <td>
                                    <table class="table-devide">
                                        <tr>
                                            <td>
                                                <div class="div2col-S">
                                                    @Html.LabelFor(m => m.ugrp_descr)
                                                    @Html.TextBoxFor(m => m.ugrp_descr)
                                                    @Html.ValidationMessageFor(m => m.ugrp_descr)

                                                    <div class=" clear">
                                                    </div>
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="div2col-S">
                                                    @Html.LabelFor(m => m.ugrp_desc)
                                                    @Html.TextBoxFor(m => m.ugrp_desc)
                                                    @Html.ValidationMessageFor(m => m.ugrp_desc)

                                                    <div class=" clear">
                                                    </div>
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="div2col-S">
                                                    @Html.LabelFor(m => m.ugrp_admin)
                                                    @Html.CheckBoxFor(m => m.ugrp_admin)
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            @Html.HiddenFor(m => m.ugrp_id, new { id = "hdfid",value="0" })
            <div id="diverror" style="display: none">
                @*Use this label to bind the server errors*@

            </div>
        </div>
    }

</body>
</html>

Master Content Page in MVC

Home.cshtml

@{
    ViewBag.Title = "Home";
    Layout = "~/Views/Home/SiteMaster.cshtml";
}


Friday, March 1, 2013

Making accordion menu using jquery in asp.net

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="AccordionMenu.WebForm2" %>

<!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 runat="server">
    <title></title>
     <script type="text/javascript" src="Scripts/jquery-1.7.1.min.js"></script>
<STYLE>
body, input{
    font-family: Calibri, Arial;
}
#accordion {
    list-style: none;
    padding: 0 0 0 0;
    width: 170px;
}
#accordion li{
    display: block;
    background-color: #FF9927;
    font-weight: bold;
    margin: 1px;
    cursor: pointer;
    padding: 5 5 5 7px;
    list-style: circle;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    border-radius: 10px;
}
#accordion ul {
    list-style: none;
    padding: 0 0 0 0;
    display: none;
}
#accordion ul li{
    font-weight: normal;
    cursor: auto;
    background-color: #fff;
    padding: 0 0 0 7px;
}
#accordion a {
    text-decoration: none;
}
#accordion a:hover {
    text-decoration: underline;
}

</STYLE>
  
 
</head>
<body>
    <form id="form1" runat="server">
    <div>
   <ul id="accordion">
    <li>
        <asp:LinkButton ID="lnkNational" runat="server">National Members</asp:LinkButton>
    </li>
    <ul>
        <asp:Panel ID="pnlCountries" runat="server"></asp:Panel>       
    </ul>
    <li>
        <asp:LinkButton ID="lnkState" runat="server">State Members</asp:LinkButton>
    </li>
    <ul>
        <asp:Panel ID="pnlStates" runat="server"></asp:Panel>
    </ul>
    <li>
        <asp:LinkButton ID="lnkDistrict" runat="server">District Members</asp:LinkButton>
    </li>
    <ul>
        <asp:Panel ID="pnlDistricts" runat="server"></asp:Panel>
    </ul>
</ul>

    </div>
    <input  type="hidden" id="hdnShow" value="0"/>
    </form>
</body>
<SCRIPT>
    $("#accordion > li").click(function () {

        if (false == $(this).next().is(':visible')) {
            $('#accordion > ul').slideUp(300);
        }
        $(this).next().slideToggle(300);
       
    });

    $(document).ready(function () {
        $('#accordion > ul:eq(0)').show();
    });

</SCRIPT>
</html>

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

namespace AccordionMenu
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LinkButton lic1 = new LinkButton();
            lic1.Text = "India";
            LinkButton lic2 = new LinkButton();
            lic2.Text = "China";
            Table tbc = new Table();
            TableRow trc1 = new TableRow();
            TableRow trc2 = new TableRow();
            TableCell tcc1 = new TableCell();
            TableCell tcc2 = new TableCell();
            tcc1.Controls.Add(lic1);
            tcc2.Controls.Add(lic2);
            trc1.Cells.Add(tcc1);
            trc2.Cells.Add(tcc2);
            tbc.Rows.Add(trc1);
            tbc.Rows.Add(trc2);
            pnlCountries.Controls.Add(tbc);

            LinkButton lis1 = new LinkButton();
            lis1.Text = "Kerala";
            LinkButton lis2 = new LinkButton();
            lis2.Text = "Tamilnadu";
            Table tbs = new Table();
            TableRow trs1 = new TableRow();
            TableRow trs2 = new TableRow();
            TableCell tcs1 = new TableCell();
            TableCell tcs2 = new TableCell();
            tcs1.Controls.Add(lis1);
            tcs2.Controls.Add(lis2);
            trs1.Cells.Add(tcs1);
            trs2.Cells.Add(tcs2);
            tbs.Rows.Add(trs1);
            tbs.Rows.Add(trs2);
            pnlStates.Controls.Add(tbs);

            LinkButton lid1 = new LinkButton();
            lid1.Text = "Ernakulam";
            LinkButton lid2 = new LinkButton();
            lid2.Text = "Trissur";
            Table tbd = new Table();
            TableRow trd1 = new TableRow();
            TableRow trd2 = new TableRow();
            TableCell tcd1 = new TableCell();
            TableCell tcd2 = new TableCell();
            tcd1.Controls.Add(lid1);
            tcd2.Controls.Add(lid2);
            trd1.Cells.Add(tcd1);
            trd2.Cells.Add(tcd2);
            tbd.Rows.Add(trd1);
            tbd.Rows.Add(trd2);
            pnlDistricts.Controls.Add(tbd);
        }
    }
}

Making accordion menu using jquery

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="AccordionMenu.WebForm3" %>

<!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 runat="server">
    <title></title>
   
<style>
.menu_list {
    width: 150px;
}
.menu_head {
    padding: 5px 10px;
    cursor: pointer;
    position: relative;
    margin:1px;
       font-weight:bold;
       background: #eef4d3 url(left.png) center right no-repeat;
}
.menu_body {
    display:none;
}
.menu_body a {
  display:block;
  color:#006699;
  background-color:#EFEFEF;
  padding-left:10px;
  font-weight:bold;
  text-decoration:none;
}
.menu_body a:hover {
  color: #000000;
  text-decoration:underline;
}
</style>
<script type="text/javascript" language="javascript" src="Scripts/jquery-1.7.1.min.js"></script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div id="firstpane" class="menu_list">
  <p class="menu_head">Header-1</p>
    <div class="menu_body">
    <a href="#">Link-1</a>
    <a href="#">Link-2</a>
    </div>
  <p class="menu_head">Header-2</p>
    <div class="menu_body">
    <a href="#">Link-1</a>
    <a href="#">Link-2</a>
    </div>
  <p class="menu_head">Header-3</p>
    <div class="menu_body">
        <a href="#">Link-1</a>
        <a href="#">Link-2</a>
   </div>
</div>
    </div>
    <script >
        //slides the element with class "menu_body" when paragraph with class "menu_head" is clicked
        $("#firstpane p.menu_head").click(function () {
            $(this).css({ backgroundImage: "url(down.png)" }).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
            $(this).siblings().css({ backgroundImage: "url(left.png)" });
        });

        //    //slides the element with class "menu_body" when mouse is over the paragraph
        //    $("#secondpane p.menu_head").mouseover(function () {
        //        $(this).css({ backgroundImage: "url(down.png)" }).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
        //        $(this).siblings().css({ backgroundImage: "url(left.png)" });
        //    });
</script>
    </form>
</body>
</html>

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...