Thursday, 29 October 2015

Add Items or Value to DropDownList in Asp.Net Using Jquery & C#

Add Items or Value to DropDownList 

Add Textbox Text  Items or Value to Dropdownlist  in Jquery & C# Coding in Dynamically  Using Asp.Net C#.

                                   DEMO

                                Download

                            HTML Coding

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Add items to dropdownlist in asp.net using jquery</title>

    <script src="jquery.min.js"></script>
    <script>
        $(document).ready(function () {
            $('#btn_add').click(function () {
                $('#ddlCourse').append(
                    $('<option></option>').text($('#txtCourse').val()));
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
    <asp:TextBox ID="txtCourse" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="btn_add" runat="server" Text="Add Item Jquery"  />
<asp:Button ID="Button1" runat="server" Text="Add Item C#" OnClick="Button1_Click" />
        <br />
<asp:DropDownList ID="ddlCourse" runat="server">
        <asp:ListItem Text="Select Course"></asp:ListItem>
        </asp:DropDownList>
    </div>
    </form>
</body>
</html>



                                   C# Coding

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

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }   
  
    protected void Button1_Click(object sender, EventArgs e)
    {
        ddlCourse.Items.Add(txtCourse.Text);
    }

}















Saturday, 24 October 2015

Bind Arraylist with DropdDownList in Asp.Net C#

Bind Arraylist with DropdDownList 

Dropdownlist Bind From The Arraylist Items Values Using in Asp.Net C#.

                                   DEMO


                              Download

                           HTML Coding

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
        <asp:DropDownList ID="ddlCourse" runat="server"></asp:DropDownList>
    </div>
    </form>
</body>
</html>



                           C# Coding

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

using System.Collections;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ArrayList Course = new ArrayList();
            Course.Add("ASP.NET");
            Course.Add("C#.NET");
            Course.Add("DropDownList");
            Course.Add("GridView");
            Course.Add("SQL Server");          
            ddlCourse.DataSource = Course;
            ddlCourse.DataBind();
        }
    }

}









Tuesday, 13 October 2015

Two Dimensional Array or 2D Array in C#

No comments    
categories: , ,
Two Dimensional Array or 2D Array


First We Use Two Dimensional Array First is Row &  Second is Column i.e[2,3] Using in C#.

              C# Coding

Row Length

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

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string[,] array = new string [2,3] { { "One""Two","Three" }, { "Four""Five","Six"} };
      
        for (int i = 0; i < 2; i++)

        {

            for (int j = 0; j <array.GetLength(0); j++)

            {

                Response.Write(array[i,j] + ",\r");

            }
        }
    }

}

 Output








Column Length

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

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string[,] array = new string [2,3] { { "One""Two","Three" }, { "Four""Five","Six"} };
      
        for (int i = 0; i < 2; i++)

        {

            for (int j = 0; j <array.GetLength(1); j++)

            {

                Response.Write(array[i,j] + ",\r");

            }
        }
    }
}


Output






Bind Array Value To Dropdownlist Using in Asp.Net C#

Bind Array Value To Dropdownlist

Bind Array & 2D Array Values To Dropdownlist Using in Asp.Net C#.

                                DEMO


                             Download

                          HTML Coding

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Bind Array Values To Dropdownlist Control Using in Asp.Net C#</title>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
   Array <asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>

    </div>
    </form>
</body>
</html>



                       C# Coding

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

public partial class DDLArray : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

// Array

            string[] arr = new string[6] { "AUSTRIA""BHUDAN""CHINA""EGYPT""FRANCE""GHANA" };
            DropDownList1.DataSource = arr;
            DropDownList1.DataBind();


// 2D Array

            string[,] arr = new string[3, 3] { { "AUSTRIA""BHUDAN""CHINA" }, { "EGYPT""FRANCE""GHANA" }, { "HUNGARY""INDIA""JAPAN" } };
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    DropDownList1.Items.Add(arr[i, j]);
                    DropDownList1.DataBind();
                }
            }
        }
    }

}
















Monday, 12 October 2015

Bind XML Data to DropDownList Control Using in Asp.net C#

No comments    
categories: , , ,
Bind XML Data to DropDownList Control

Bind Extensible Markup Language (XML) Xml List Data Bind To Dropdownlist Control Using in Asp.Net C#.

                                   DEMO


                         Download

                       HTML Coding

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
       
        Course
        <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
    </div>
    </form>
</body>
</html>


                           C# Coding

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

using System.Data;

public partial class Xml : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataSet ds = new DataSet();
            ds.ReadXml(Server.MapPath("XMLFile.xml"));

            DropDownList1.DataTextField = "coursename";

            DropDownList1.DataValueField = "courseid";

            DropDownList1.DataSource = ds;
            DropDownList1.DataBind();

        }
    }

}