- How to data bind a DropDownList on page load

How to data bind DropDownList on page load
The following c# example code demonstrate us how can we populate a DropDownList web server control with items on Page Load event. We can populate DropDownList control from many types of Data Source objects such as Array, Dictionary, ArrayList, SqlDataSource, ObjectDataSource etc.

Page Load event allow us to data bind a DropDownList control while the page is initially loaded on web browser. We also can perform only one time data binding by checking the page is not the PostBack stage. Page.IsPostBack allow is to determine whether the page is first time loaded or it is in post back mode. So we data bind a DropDownList at a time and each time the page in post back mode, it will display the DropDownList with items.

In the bellow example code, we initializes a String Array object and populate it with items. Then we define the DropDownList control's DataSource to Array Object. Next, we call the DropDownList DataBind() method to data bind DropDownList with Array DataSource. Finally, web browser render a DropDownList control which items are generated from Array.

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Page_Load(object sender, System.EventArgs e)
        string[] controls = { "TreeView", "SiteMapPath", "LoginName", "Timer", "FormView"};
        DropDownList1.DataSource = controls;

<html xmlns="">
<head id="Head1" runat="server">
    <title>How to data bind DropDownList on page load</title>
    <form id="form1" runat="server">
        <h2 style="color:Red">DropDownList: DataBind Page_Load</h2>
             Text=" controls"

More examples