ListBox AppendDataBoundItems property in c#

ListBox Example: How to use AppendDataBoundItems property
Sometime we need some static listItem when we populate a ListBox from various data source. We can easily do it by use AppendDataBoundItems ListBox property. Here I show a simple example of how to use AppendDataBoundItems property in ListBox control.

In this example first we need to create an xml file name Tags.xml. We use it for ListBox XmlDataSource. Here is the source code of Tags.xml file.

<?xml version="1.0" encoding="utf-8" ?>
  <Option Name="asp:AccessDataSource"/>
  <Option Name="asp:AdRotator"/>
  <Option Name="asp:AppearanceEditorPart"/>
  <Option Name="asp:BehaviorEditorPart"/>
  <Option Name="asp:BulletedList"/>
  <Option Name="asp:Button"/>
  <Option Name="asp:Calendar"/>
  <Option Name="asp:CatalogZone"/>

ListBox AppendDataBoundItems
Now create a Web Form name ListBoxAppendDataBoundItems.aspx. Then add an XmlDataSource Control and a Listbox Control. We also add two static ListItem. When populate the ListBox from XmlDataSource we want to see this two ListItem in ListBox. So we need set the ListBox's AppendDataBoundItems property value true. Here is the source code of ListBoxAppendDataBoundItems.aspx file.

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

<!DOCTYPE html>

<script runat="server">


<html xmlns="">
<head runat="server">
    <title>ListBox Example: How to use AppendDataBoundItems property in ListBox</title>
    <form id="form1" runat="server">
        <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/Tags.xml">
More examples