Saturday, July 12, 2014

Add row after in DropDownList binding with SQLDataSource in ASP.NET C#

After binding a DropDownList  in C# using SQLDataSource its showing data all time what ever its bind from the database's table. But if you an one need to add any additional data into the DropDownList  then how to do.

In this article I will show you how to add a row  in a DropDownList  after binding with a SQLDataSource.

First bind a DropDownList with a SQLDataSource and the in the page_Load event write down the following code.

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
         ddl1.Items.Insert(0, new ListItem("-Select-", "0"));
         ddl1.DataBind();
    }
}

Now run the project and see the change. Enjoy... :)

0 comments:

Post a Comment

Follow by Email

Popular Posts

Pageviews