开发者

asp.net sql datasource bounded devexpress combobox add item

Hello i have开发者_运维知识库 devexpress combobox bounded with a sql datasource.I'am autocompleting items from datasource by using

OnItemsRequestedByFilterCondition function

i am filtering the items and binding filtered datasource to combobox

i want to add a "select All" item to top of the filtered results.

İ have already tried

combobox.Items.Add(0,new ListEditItem(-1,"Select All"));

but that does not work. I found soluiton for other datasources such list etc but not for sql datasource.Any clue would be helpful thank you.


combobox.Items.Add(0,new ListEditItem(-1,"Select All")); might be getting called before when you bind the combobox to the datasource.

The best way would be add this same field on the data source or add the item after you have binded the combobox with the data.


Looking at the different method signatures for Add(), when Add accepts 2 parameters it takes (string text, object value). Insert() on the other hand is accepts (int index, ListEditItem item). Try to use the Insert method as follows:

combobox.Items.Insert(0, new ListEditItem("Select All", -1);


The way I do this is to add the -1 item before the data is bound

Problem I see you have is your binding to SQL data directly where I bind to objects that are derived from SQL calls. For example:

var contractors = ContractorCollection.GetAll().Active();
contractors.Sort(new Contractor.NameAscending());

contractors.Insert(0, new Contractor() { ID = -1, Name = "Not Applicable or Required" });
this.cboContractors.TextField = "Name";
this.cboContractors.ValueField = "ID";
this.cboContractors.DataSource = contractors;
this.cboContractors.DataBind();

As you can see I am using a Collection which is built from a SPROC call internally. This populates the collection which is then bound in code.

I suspect your binding to a SQLDataSource control?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜