Adding item to Databoud Drop Down control

It was quite a struggle for me to add a string “All” to a data bound drop down list box. It was really becoming for me a challenge as everytime my client would bring this point and when I tell my problem he would give some stupid way to solve this issue. So atlast taken this challenge.

Suppose you have drop down list box, and you have SqlDataSource to bound it some data. In my case I was trying to populate with some user list. Now there was an option for All which I have to add initially I added a checkbox next to the dropdown but then I got a way to do it googling. The solution is to use the Insert method to add an list item to the drop down

ListItem item = new ListItem(“All”, “All”);

cmbUseList.Items.Insert(0,item);//The first is the index

Thanks to the customer who challenged to bring the good solutions.

ADO.NET DataTable

We always need to create temporary tables using DataTable class in ADO.NET. The following is the way to create a table considering the table schema to be custid,custname,dob.

DataTable custDT = new DataTable(“Customer”);

 The above created a DataTable with 3 columns.