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();
        }
    }

}


First Add New Web Form - Add Dropdownlist From Toolbox 





Next - Create Arraylist Add List For Array list  & Bind To Dropdownlist




0 comments:

Post a Comment