Thursday, 10 January 2013

Adding TabPanels Programatically in ASP.NET AJAX C#


Adding TabPanels Programatically in ASP.NET AJAX C#



Step 1) Create WebPage .aspx

Step 2)  Include following References
              System.Data;
              System.Data.SqlClient;


Step 3)  Build DataSet using  AdventureWorks Database.
               Here I am using 2 tables 
                1.SalesPerson
                2.Employee


 void BuildDataSet()
        {
        SqlConnection conn = new SqlConnection(@"server=.\sqlexpress2012;
                            database=AdventureWorks2012;
                            trusted_connection=yes;");

        SqlDataAdapter ad = new SqlDataAdapter("select * from
[AdventureWorks2012].[Sales].[SalesPerson] as SalesPerson; "+
        "select * from [AdventureWorks2012].[HumanResources].
[Employee] as Employee",
            conn);

        ad.Fill(ds);
        conn.Close();
       
        }


Step 4)    Programatically Creating a GridView in ASP.NET using C#

  void AddTabPanels()
        {
        TabContainer1.Tabs.Clear();

        foreach(DataTable tb in ds.Tables){
        AjaxControlToolkit.TabPanel panel = new AjaxControlToolkit.TabPanel();
        panel.HeaderText = tb.TableName;
        GridView view = new GridView();
        view.EmptyDataText = "No data found";
        view.ShowHeaderWhenEmpty = true;
        view.DataSource = tb;
        view.DataBind();
        view.AlternatingRowStyle.BackColor = System.Drawing.Color.Teal;
        view.AlternatingRowStyle.ForeColor = System.Drawing.Color.Wheat;
        panel.Controls.Add(view);
        TabContainer1.Tabs.Add(panel);
       
        }

Note: Every PostBack Dynamic controls needs to be created.

Step 5) Bind in Page_Load()

        DataSet ds = new DataSet();
        protected void Page_Load(object sender, EventArgs e)
        {
            BuildDataSet();
            AddTabPanels();
        }


Step 6) Run the Web page.



Adding TabPanels Programatically in ASP.NET AJAX C#,Creating tabpanels in ajax


Adding TabPanels Programatically in ASP.NET AJAX C#/Vb.NEt,Creating tabpanels in ajax





 




Tags:Adding TabPanels Programatically in ASP.NET AJAX C#,AJAX Tabcontainer in C#, Adding  Tab Panels Programatically, Adding TabPanels Dynamically. AJAX TAB Container Example, AJAX TABCONTAINER Tutorial