Reputation: 219
Sorry if the title is a bit vague - it is difficult to capture what i want to do in one sentence, so I'll quickly explain what I want to achieve.
I want to bind an SQL table to a comboBox and have all its values (Item names for example) but I also wish to add one of my own items into the same comboBox, separate from the table (For example - "Add new" should then be inserted at the bottom of the list after the SQL table values have been loaded in the comboBox).
Is this possible? If so, how do I do it?
Thanks guys!
Upvotes: 0
Views: 37
Reputation: 31
You can assign datasource in code-behind like this.
cmb1.DataSource=dt;
cmb1.DataBind();
cmb1.Items.Insert(dt.Rows.Count,new ComboBoxItem("Add New","0"));
cmb1.appenddatabounditems="true";
Upvotes: 3
Reputation: 14669
You can use Insert, you have to specify index and new item to add in list.
cmb1.Items.Insert(tabl.rows.count,"Add new");
OR
ComboboxItem item = new ComboboxItem();
item.Text = "Add new";
item.Value = 0;
cmb1.Items.Add(item);
If you not specify any index it will append at last
Upvotes: 0