show-notice
hide-notice

Saturday, 13 July 2013

How to add the item to ListBox by coding in Asp.Net



Introduction


I will explain How to add the item to ListBox by coding in Asp.Net.



Description


ASP.NET ListBox & DataBinding ListBox is used to read data from a Database conditioned.
SelectionMode = "Multiple".


 
Example



<%@
page language="C#" autoeventwireup="true" codefile="How-to-additem-ListBox-coding-c.aspx.cs"
    inherits="How_to_additem_ListBox_coding_c"
%>
<!DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head
runat="server">
    <title>How to
add the item to ListBox by coding</title>
</head>
<body>
    <form id="form1"
runat="server">
    <div>
       
<
asp:listbox id="ListBox1"
runat="server"
height="201px"
selectionmode="Multiple"
           
width="388px"></asp:listbox>
    </div>
    </form>
</body>
</html>
 


C#




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
public partial
class How_to_additem_ListBox_coding_c
: System.Web.UI.Page
{
    protected void Page_Load(object
sender, EventArgs e)
    {
        {
           
string strConn;
           
string sqlCustomers;
           
strConn = "Provider=Microsoft.JET.OLEDB.4.0;data source="
+ Server.MapPath("App_Data/Northwind.mdb");
           
sqlCustomers = "SELECT CustomerID,ContactName, Address,City";
           
sqlCustomers += " FROM Customers";
           
OleDbConnection Conn = new OleDbConnection(strConn);
           
Conn.Open();
 

 

SHARE THIS POST   

0 comments :

Post a Comment

Design by Gohilinfotech | www.gohilinfotech.blogspot.com