List box HTML code:
<%@ page language= "C #" autoeventwireup= "true" codefile= "Default2.aspx.cs" inherits= "DEFAULT2"%><! DOCTYPE html> List box background C # code
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.web.ui.webcontrols;public partial class default2:system.web.ui.page{protected void Page_Load (object sender, E Ventargs e) {if (! IsPostBack) {Testdatacontext context = new Testdatacontext (); Listbox1.datasource = context. Nation; Listbox1.datatextfield = "Name"; Listbox1.datavaluefield = "Code"; Listbox1.databind (); }} protected void button1_click (object sender, EventArgs e) {//Find checked item foreach (ListItem item in Lis Tbox1.items) {if (item. Selected) {if (! ListBox2.Items.Contains (item)) {LISTBOX2.ITEMS.ADD (item); }}}} protected void Button2_Click (object sender, EventArgs e) {foreach (ListItem ite M in Listbox1.items) {if (! LIstBox2.Items.Contains (item)) {LISTBOX2.ITEMS.ADD (item); } } }}
WB list Box