如何在类别表中使用数据列表控件 [英] how to use datalist control in case Category Table
本文介绍了如何在类别表中使用数据列表控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个sql语句......
I have this sql statement......
create table categories
( id integer not null primary key
, name varchar(37) not null
, parentid integer null
, foreign key parentid_fk (parentid)
references categories (id)
);
我想先显示其父级,然后单击父级以显示其子类别
使用数据列表.我有类似
的数据
And i wanna display its Parent first and by clicking parent show its sub category
using datalist.. I''ve data like
id name parentid
1 animal NULL
2 vegetable NULL
3 mineral NULL
4 doggie 1
5 kittie 1
6 horsie 1
7 gerbil 1
8 birdie 1
9 carrot 2
10 tomato 2
11 potato 2
12 celery 2
13 rutabaga 2
14 quartz 3
15 feldspar 3
16 silica 3
17 gypsum 3
18 hunting 4
19 companion 4
20 herding 4
21 setter 18
22 pointer 18
23 terrier 18
24 poodle 19
25 chihuahua 19
26 shepherd 20
27 collie 20
有人帮我吗...
在此先谢谢您
Is anyone help me...
Thank you in advance
推荐答案
您可以在两个sql语句中完成此操作.
以下查询将获取您的所有父类别.
Hi,
You can do it in two sql statements.
The below query will get all your parent categories.
Select id, name from categories where parentid is NULL
然后,当用户选择一个类别时,您便知道其ID,因此只需选择所有父类别与所选类别匹配的子类别.
Then when the user selects a category you know its Id, so then you just select all the child categories which have a parent category matching the selected category.
//Pass in parameter @ParentId which matches the Category clicked.
Select id, name from categories where parentid = @ParentId
这篇关于如何在类别表中使用数据列表控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文