类别下拉过滤器应该只包含实际有数据的类别?如何生成动态下拉列表? [英] Category dropdown filter should only include categories that are actually has data ? How to generate dynamic dropdown ?

查看:62
本文介绍了类别下拉过滤器应该只包含实际有数据的类别?如何生成动态下拉列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个从数据库填充的下拉列表。这实际上是一个过滤器。

关于此下拉列表的选定索引更改我在gridview中显示与所选索引的id相关的数据。



但是现在我想要做的是我想只显示下拉列表中的那些类别肯定会给我数据..选择的索引中不应该有其他部分更改..如果找不到与所选下拉列表ID相关的无数据可用 。我想从数据库中确定100个确定的类别..





我怎么能这样做plz建议。

Hi,

I have a dropdown which gets filled from databse . this is actually a filter.
on selected index change of this drop down i am showing data in gridview which is related to that id of selected index.

But now what i want to do is i want to display only those categories in dropdowns which are surely give me the data .. There should not be else part in selected index changed .. if nothing found related to selected dropdown id then "No data available". I want 100 persent sure categories from databse ..


How can i do that plz suggest .

推荐答案

Torakami写道:
Torakami wrote:

但现在我想要做的是我只想在下拉列表中显示那些类别肯定会给我数据

But now what i want to do is i want to display only those categories in dropdowns which are surely give me the data

这不是什么大不了的事。只需加载与详细信息表数据匹配的数据。

例如,您有两个表Country& City。

It's not a big deal. Just load the data which matches the details table data.
For example, you have two tables Country & City.

------------------------------
Country
------------------------------
CountryID | CountryName
------------------------------
1         | US
2         | UK
3         | Canada
------------------------------
City
------------------------------
CountryID CityID | CityName
------------------------------
1        |1      | New york
1        |2      | Los Angles
2        |1      | London
2        |2      | Luton
------------------------------



现在你必须编写一个查询来加载可用国家(用于下拉列表),如下所示


Now you have to write a query to load Available Countries(for Dropdown) like below

SELECT B.CountryID,A.CountryName FROM Country A, City B
WHERE A.CountryID=B.CountryID

现在它只加载有城市的国家。

Now it'll load only Countries which has cities.

------------------------------
Available Countries
------------------------------
CountryID | CountryName
------------------------------
1         | US
2         | UK
------------------------------



就是这样。


That's it.


这篇关于类别下拉过滤器应该只包含实际有数据的类别?如何生成动态下拉列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆