Thursday, 1 March 2012

.Net Beginners : How to insert an item to the specified location in the DropDownList or ListBox?

You can also insert ListItem at specific location.
In .Add Method Items are append.
There is one method ".Insert" to insert items as specified location.

Syntax :
DropDownList.Items.Insert(index as integer , System.Web.Ui.WebControls.ListItem)
Hear index is based on zero.

Example :
        Dim objListItem As ListItem
        objListItem = New ListItem("Software", 1)
        ddlProduct.Items.Insert(1, objListItem)

In this example the item is inserted at 2nd place because index is zero based.

No comments:

Post a comment