开发者

Filtering SqlDataSource with multiple dropdownlists

I have an SqlDataS开发者_开发知识库ource at the moment, which I want to be able to be filtered using 3 DropDownList's. Basically, each DropDownList contains values for a certain column on the table, so when they choose one of the values, the SqlDataSource only shows values with that value in the relevant column.

So my table is somewhat like this:

ID (primary key)

ManufacturerID

ItemTypeID

UnitTypeID

And the 3 DropDownList's contain the following:

Manufacturers (value = ManufacturerID)

ItemTypes (value = ItemTypeID)

UnitTypes (value = UnitTypeID)

My filter expression for the datasource is currently like this, but it doesn't seem to work unless all 3 boxes have a value selected, which is not ideal. Any ideas guys? My filterexpression is below:

ItemTypeID = {0} OR ManufacturerID = {1} OR UnitTypeID = {2} OR (ItemTypeID = {0} AND ManufacturerID = {1}) OR (ItemTypeID = {1} AND UnitTypeID = {2}) OR (ManufacturerID = {1} AND UnitTypeID = {2}) OR (ItemTypeID = {0} AND ManufacturerID = {1} AND UnitTypeID = {2})


You can add the filter criteria one by one like the following:

// Idea not code..

yourFilterExpression = "";
if (dropDownList1.SelectedValue != null)
 filterExpression = // filter expression 1
if (dropDownList2.SelectedValue != null)
 filterExpression += // filter expression 2

Good luck!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜