ListBox

ListBox value by using property.


Note:
ListBox value start with zero(0).
Index Change event default property of ListBox.

step:

s1) Drop Down ListBox.
s2) go to property by Default Rows 4 set it as 1.
s3)Click on master tag of listBox.
s4)Click on Edit item
s5)One option ADD Click on it.
s6)Give value.

ListBox value by using Code.

Property:
listBox have one property items therefore we write ListBox2.Items.Add(value); When we Add the value we used items  otherwise write text eg.ListBox2.Text


We mostly used code on button click :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class listbox : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ListBox2.Items.Add("nagpur");
        ListBox2.Items.Add("mumbai");
        ListBox2.Items.Add("delhi");
        ListBox2.Items.Add("pune");
        ListBox2.Items.Add("hydrabad");
    }
}

Position of Values in listbox is called index.
e.g. 0
       1
       2
       3
       4

Note:
Any ListBox event make AutoPostBack as true  otherwise it is not true.

Popular Posts