Tuesday, April 24

Create Dynamic Ajax Tabcontainer With Dynamic Repeater Having Linkbuttons with Raising Click events

Here i am Describing About how to create Ajax Tabcontainer dynamically as well as how to bind repeater inside that Tab.Finally i have to bind data with inner linkbuttons of repeater from database.

Here is my Database diagram:-














Here is my Page OverView:-










































Here is my Source code:-

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

<!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>Om Namah Shivaya</title>
    <h1>Dynamic Ajax TabContainer With dynamic repeater Having linkbuttons With click Event(created by Shibashish Mohanty)</h1>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
   
        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
   
    </div>
    </form>
  
</body>
</html>

Here is my Page Code Behind:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI.HtmlControls;

public partial class DynamicTabWithRepeaterAndLinkButton : System.Web.UI.Page
{
    AjaxControlToolkit.TabContainer DynamicTab;
    protected void Page_Load(object sender, EventArgs e)
    {
        DataClassesDataContext dc = new DataClassesDataContext();
        var x = GetTabInfo();

        for (int i = 0; i < x.Count(); i++)
        {
            Table tb1 = new Table();
            TableRow tr1 = new TableRow();
            TableCell tc1 = new TableCell();

            DynamicTab.Tabs[i].Controls.Add(tb1);
            var y = GetNewItemInfo(x[i].PrID);
            #region comment for Gridview

            ////DropDownList drplist = new DropDownList();
            //GridView datalisting = new GridView();

            ////datalisting.RepeatColumns = 1;

            ////for (int j = 0; j < y.Count(); j++)
            ////{//
            //// datalisting.ID = y[j].MenuID.ToString();

            //datalisting.DataSource = y;
            //datalisting.DataBind();
            //// datalisting.ItemTemplate = Page.LoadTemplate("MenuData.ascx"); // what should I do here??
            ////
            ////drplist.ID = y[j].MenuID.ToString();

            ////drplist.DataSource = y;
            ////drplist.DataTextField = "MenuName";
            ////drplist.DataBind();
            ////drplist.AutoPostBack = true;
            ////if (drplist.SelectedIndex == 1)
            ////{
            ////   Label1.Text ="hello Friend";
            ////}

            ////}

            //tc1.Controls.Add(datalisting);
            //tr1.Cells.Add(tc1);
            //tb1.Rows.Add(tr1);
            #endregion

            #region comment for Repeater

            string connecStr = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(connecStr);
            SqlDataAdapter da = new SqlDataAdapter("select * from ProjectMenu  where PrID =" + x[i].PrID + "", con);

            DataSet myDataSet = new DataSet();
            da.Fill(myDataSet);
            Repeater Repeater1 = new Repeater();
            Repeater1.DataSource = myDataSet;
            Repeater1.DataBind();
            foreach (RepeaterItem repeatItem in Repeater1.Items)
            {
                // if condition to add HeaderTemplate Dynamically only Once
                if (repeatItem.ItemIndex == 0)
                {
                    RepeaterItem headerItem = new RepeaterItem(repeatItem.ItemIndex, ListItemType.Header);
                    HtmlGenericControl hTag = new HtmlGenericControl("h4");
                    hTag.InnerHtml = "Menu Names";
                    repeatItem.Controls.Add(hTag);
                }
                // Add ItemTemplate DataItems Dynamically
                RepeaterItem repeaterItem = new RepeaterItem(repeatItem.ItemIndex, ListItemType.Item);
                LinkButton lKbt = new LinkButton();
                lKbt.ID = string.Format("{0}", myDataSet.Tables[0].Rows[repeatItem.ItemIndex]["MenuID"]);
                lKbt.CommandArgument = lKbt.ID;
                lKbt.Command += new CommandEventHandler(lKbt_Command);
                lKbt.Text = string.Format("{0} {1} <br/>", myDataSet.Tables[0].Rows[repeatItem.ItemIndex]["MenuName"], myDataSet.Tables[0].Rows[repeatItem.ItemIndex]["CreatedDate"]);
                Label lbl = new Label();
                lbl.Text = string.Format("{0} ", myDataSet.Tables[0].Rows[repeatItem.ItemIndex]["CreatedDate"]);
                Label lb = new Label();
                lb.Text = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ";
                repeatItem.Controls.Add(lbl);
                repeatItem.Controls.Add(lb);
                repeatItem.Controls.Add(lKbt);
              
                // Add SeparatorTemplate Dynamically
                repeaterItem = new RepeaterItem(repeatItem.ItemIndex, ListItemType.Separator);

                //If you want to separate Each row With a header then uncomment below Line

                //LiteralControl ltrlHR =new LiteralControl();
               // ltrlHR.Text = "<hr />";
                //repeatItem.Controls.Add(ltrlHR);
            }

            tc1.Controls.Add(Repeater1);
            tr1.Cells.Add(tc1);
            tb1.Rows.Add(tr1);
            #endregion
        }
        PlaceHolder1.Controls.Add(DynamicTab);
    }
    protected void Page_Init(object sender, EventArgs e)
    {
        try { createTab(); }
        catch { }

    }
    private List<Project> GetTabInfo()
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            return (from c in context.Projects

                    select c).ToList();
        }
    }
    private List<ProjectMenu> GetNewItemInfo(int Proid)
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            return (from n in context.ProjectMenus
                    where n.PrID == Proid

                    select n).ToList();
        }
    }
    private void createTab()
    {
        DynamicTab = new AjaxControlToolkit.TabContainer();


        DataClassesDataContext dc = new DataClassesDataContext();
        var x = GetTabInfo();


        for (int i = 0; i < x.Count(); i++)
        {
            TabPanel TbPnlCategry = new TabPanel();
            TbPnlCategry.HeaderText = x[i].PrName;
            TbPnlCategry.ID = x[i].PrID.ToString();
            DynamicTab.Tabs.Add(TbPnlCategry);
        }
    }
    void lKbt_Command(object sender, CommandEventArgs e)
    {
        Page.RegisterStartupScript("ScriptDescription", "<script type=\"text/javascript\">alert('" + e.CommandArgument.ToString() +" "+ "Shibashish Mohanty');</script>");
       
    }
}

After running The page It will display As:-




After Click on  The Linkbutton It will display As:-








































Monday, April 23

Create Dynamic Accordion With multiple AccordionPane

Here i am Going to Post My Both Source And Page Behind code

My Source Code:-



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

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!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>
</head>
<body>
   <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:Panel ID="Panel1" runat="server">

        </asp:Panel>
    </div>
    </form> 
</body>
</html>

My Page Behind Code:-


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Accordion acrd = new Accordion();
        acrd.ID = "Accordion1";
        acrd.BorderStyle = BorderStyle.Solid;
        acrd.BorderColor = System.Drawing.Color.Black;
        acrd.BackColor = System.Drawing.Color.Gray;
        //This is for first Accordian Pane
        AccordionPane acpane = new AccordionPane();
        acpane.ID = "Shibashish";

       
        Label lbl = new Label();
        lbl.Text = "jay(Click Me To Open)   Accordionpane1";
        acpane.HeaderContainer.Controls.Add(lbl);
        acpane.HeaderContainer.BorderStyle = BorderStyle.Double;
        acpane.HeaderContainer.BorderColor=System.Drawing.Color.Red;
        acpane.HeaderContainer.BackColor = System.Drawing.Color.Green;
          TextBox txt = new TextBox();
        txt.Text = "om namah shivaya";
        acpane.ContentContainer.Controls.Add(txt);
        acpane.ContentContainer.Controls.Add(new LiteralControl("</br>This is my dynamic Accordian application"));
        acrd.Panes.Add(acpane);

       
        //This is for Second Accordian Pane
        AccordionPane acpane1 =  new AccordionPane();
        acpane1.ID = "Mohanty";
        acpane1.HeaderContainer.Controls.Add(new LiteralControl("Jagdish(Click Me To Open)    Accordionpane2"));
        acpane1.HeaderContainer.BorderStyle = BorderStyle.Double;
        acpane1.HeaderContainer.BorderColor = System.Drawing.Color.Blue;
        acpane1.HeaderContainer.BackColor = System.Drawing.Color.YellowGreen;
        TextBox txt1 = new TextBox();
        txt1.Text = "om namah ganesh";

        //Added the contents object in AccordionPane
        acpane1.ContentContainer.Controls.Add(txt1);

        //Added the AccordionPane object in Accordion
        acrd.Panes.Add(acpane1);
        //Added the Accordion object in Panel
        Panel1.Controls.Add(acrd);

       
    }
}



Thanks Shibashish Mohanty

Tuesday, April 17

Calling Different Page into a Div Of Another Page Using Javascript With progressBar

Hi i am explaining you here how to call a javascript function from server side code for retrieving Another page into the Div of a same page

Here is my javascript function


<script src="Js/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script language ="javascript" >
function f1() {


$("#shibashish").load("TestMaster.aspx", {}, function () { });
}
</script>


Here is my Sourcecode
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="Js/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Js/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script language ="javascript" >
        function f1() {
 

            $("#shibashish").load("TestMaster.aspx", {}, function () { });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
      <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
      <%--<input type ="button" value ="get page" onclick ="f1()" />--%>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
        <asp:Button
            ID="Button1" runat="server" OnClick="Button1_Click"  Text="Button" />
        </ContentTemplate>
        </asp:UpdatePanel>
 
        <br />
       Hi this is static
       <asp:UpdateProgress ID="UpdateProgress1" class="UpdateProgress1" runat="server">
 <ProgressTemplate>
  <img src="images/animations-photoshop-26.gif" style="height: 40px" />
 </ProgressTemplate>
 
 </asp:UpdateProgress>
       <br />
       <div id="shibashish">
         hi this dynamic
       </div>
    </div>
    </form>
</body>
</html>


Here is my event code

protected void Button1_Click(object sender, EventArgs e)
   {
       System.Threading.Thread.Sleep(3000);
      string script = "<script language="'javascript'">f1();</script>";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), script, false);
}

Thanks Shibashish Mohanty

.

ShibashishMnty
shibashish mohanty