Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi hi

in my application i am using table called teacherdetailloading which will to bound combobox

here is my piece of code:
    combobox2.DataSource = ds.Tables["teacherdetailloading"];//ds is dataset
combobox2.DisplayMember = "name";
combobox2.ValueMember = "name";

if i try to add new item called select to that combobox it will display an error message.

Item collection cannont be modified when the datasource is set.

i have tried this concepts

//DataTable Dt1 = new DataTable();
             //Dt1.Columns.Add("district");
             //Dt1.Rows.Add("select");
             //Dt1.Merge(ds.Tables["teacherdetailloading"]);

             combobox2.DataSource = ds.Tables["Dt1"];
             combobox2.DisplayMember = "district";
             combobox2.ValueMember = "district";

but it will not work. if anyone have any other way of doing it help me.

thanks in advance.
Posted
Updated 24-Apr-12 20:25pm
v2

Hi,
You can not add item to a control which a datasource has been bound to as the Excaption message says. Merging DataTables is fine. Take a look at this post which has a sample of merging two DataTable (look at the first solution in the post):

how to merge two data set[^]

I hope it helps,
Cheers
 
Share this answer
 
v2
select smart tag...

then add item text "select", manually in listitem collection editor...

then write binding code in behind...

it works gud....
 
Share this answer
 
After binding the dropdown type this code

combobox2.Items.Insert(0,new ListItem("Select", "0"));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900