In this article we will introduce with How to add item in ListBox using DataSource in ASP.NET
How to add item in ListBox using DataSource in ASP.NET
In this example You can see how we can add item in ListBox using DataSource. In this example we use SqlDataSource for bind the data with ListBox.
ListBoxDataSource.aspx (Design Page):
ListBoxDataSource.aspx (source code):
<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master" AutoEventWireup="true" CodeFile="ListBoxDataSource.aspx.cs" Inherits="ListBoxDataSource" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div> <h2 style="color: Green"> How to add item in ListBox using <br /> DataSource in ASP.NET 4, C#</h2> <asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="StudentName" DataValueField="StudentName" Width="174px"></asp:ListBox> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ChartDatabaseConnectionString %>" SelectCommand="SELECT [StudentName] FROM [Student]"></asp:SqlDataSource> </div> </asp:Content>
[ 0 ] Comments