如何绑定下拉列表 [英] how to bind dropdownlist

查看:100
本文介绍了如何绑定下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

我怀疑如何绑定下拉列表.我有一张桌子.

Id 类别名称 主要类别ID 重量
1 课程 0 0
2 科学 1 1
3 非课程 0 0
4 物理 2 2
5 代理 3 1
6 凹面镜 4 3

在此表中,主要类别表示要归入该类别的子类别,权重表示该子类别级别.

对于上表,我要绑定下拉菜单,例如这种格式

课程
-科学
物理
---凹面镜
非课程
-代理


谁能知道解决方案,请帮助我.您经常在文章发布网站中看到此信息.如果有人有想法告诉我,

谢谢,

Hi friends,

I have a doubt how to bind drop down list. i have a table.

IdCategory NameMain Category IdWeight
1Curriculum00
2Science11
3Non-Curriculum00
4Physics22
5Acting31
6Concave Lense43

In this table the main category is denotes the subcategory which will come under that category the weight denotes that sub category level.

for the above table i want to bind drop down like this format

Curriculum
-Science
--Physics
---Concave Lense
Non-Curriculum
-Acting


Can any one know the solutions please help me. u often see this is in article posting sites. if any one have the idea tell me,

Thanks,

推荐答案

请按照以下步骤操作:

*通过使用SqlConnection SqlDataAdapter和DataSet提取要与DropDowlList绑定的信息.

*使用以下步骤将数据绑定到DropDownList
Follow the below steps :

* Extract the Information you want to bind the DropDowlList with, by making use of SqlConnection SqlDataAdapter and DataSet.

* Use the following steps to bing the Data to the DropDownList
DropDownList1.DataSource = dataSetName
DropDownList1.DataTextField = "FieldName";
DropDownList1.DataValueField = "FieldName";
DropDownList1.DataBind();




如果要从绑定"值中为DropDownList设置默认值,则可以使用DropDownList1.SelectedValue属性.


BR//
Harsha




If you want to set a default value to the DropDownList from the Bind values you can use the DropDownList1.SelectedValue property.


BR//
Harsha




在数据库中放置一个额外字段作为rangingOrder,并在获取数据时写入以通过orderOrder


put an extra field in database as arrangeOrder and when you fetch data write to get orderBy arrangeOrder


这篇关于如何绑定下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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