.net中的下拉菜单选择 [英] dropdown selection in .net

查看:142
本文介绍了.net中的下拉菜单选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个类别中选择,然后显示子类别在dropdown.when选择其它类别,然后显示子类别的下拉水净化...所以我如何能做到这一点????

解决方案

你好,

您的数据库第一个表(Category_master)中必须有2个表,在其中存储具有其唯一ID(PK)和类别名称的类别.
在第二个表Category_Detail中,其中存储了所有带有CategoryId(FK)的子类别.

在下拉列表中,根据所选项目或值,所选索引已更改的事件可以填充子类别.

您需要在类别下拉列表中绑定子类别下拉列表.所选索引已更改.




我认为您的下拉菜单多种多样,并且您希望针对将一个下拉菜单更改为另一个下拉列表进行过滤.如果是这样,则可以使用dropdown的selectedindexchange事件.

在第一个下拉列表的选定索引更改上,将第一个下拉列表的值传递给您的加载方法,然后将结果填充到下一个下拉列表.

快乐编码:)


像这样尝试

在页面加载事件下加载dropdown1,然后在dropdownlist1下绑定dropdown2所选索引已更改事件
例如:

 cmd =新的SqlCommand(" ,等等)
        博士= cmd.ExecuteReader()

 DropDownList1.DataSource = dr
        DropDownList1.DataTextField = " 
        DropDownList1.DataValueField = " 

        DropDownList1.DataBind()
        关闭()
        con.关闭()



在dropdownlist1下选择的索引已更改事件

受保护的子DropDownList1_SelectedIndexChanged(ByVal发送者 As 对象,ByVal e  As 系统. EventArgs)处理DropDownList1.SelectedIndexChanged
        con.打开()
        cmd =新的SqlCommand("  + DropDownList1.SelectedItem.ToString( )+ " ,con)
        博士= cmd.ExecuteReader()
        DropDownList2.DataSource = dr
        DropDownList2.DataTextField = " 
        DropDownList2.DataValueField = " 

        DropDownList2.DataBind()
        关闭()
        con.关闭()

  结束


if one category select then display subcategory in dropdown.when select other category then display othe dropdown of subcategory...so how can i do it????

解决方案

Hi,

you must have 2 table in your database 1st table(Category_master) where you store category with his uniq id(PK),and category name.
and in second Table Category_Detail where store all sub category with CategoryId(FK).

on dropdown selected index changed event according to either selected item or value you can fill Sub category.

you need to bind subcategory dropdown at the time of categorydrop down selected index changed.


Hi,

I think you are having mulitiple dropdowns and you want filteration on the changing of one dropdown for another dropdown. If it is like that, you can use selectedindexchange event of dropdown.

On the selected index change of the first dropdown, pass the value of the first dropdown to the your load method, and fill the result to the next drop down.

Happy Coding :)


try like this

under page load event load the dropdown1 then bind dropdown2 under dropdownlist1 selected index changed event
EX:

cmd = New SqlCommand("select * from sample", con)
        dr = cmd.ExecuteReader()

 DropDownList1.DataSource = dr
        DropDownList1.DataTextField = "name"
        DropDownList1.DataValueField = "name"

        DropDownList1.DataBind()
        dr.Close()
        con.Close()



under dropdownlist1 selected index changed event

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        con.Open()
        cmd = New SqlCommand("select * from sample1 where name='" + DropDownList1.SelectedItem.ToString() + "' ", con)
        dr = cmd.ExecuteReader()
        DropDownList2.DataSource = dr
        DropDownList2.DataTextField = "name"
        DropDownList2.DataValueField = "name"

        DropDownList2.DataBind()
        dr.Close()
        con.Close()

  End Sub


这篇关于.net中的下拉菜单选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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