.net下拉编码帮助 [英] .net dropdown coding help

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

问题描述

如果一个领域从下拉菜单(即IT)中进行选择,那么我们要显示与该领域相关的所有子类别,即IT在另一个下拉列表中.我会做吗???? plz可以帮助我...

If one feild select from dropdown ie(IT) then we want to display all sub category which is related to that feild ie.(IT) in another dropdown..nd also same to other feild....so what can i do?????plz help me...

推荐答案

如果您在页面上使用数据绑定,并且子类别与以下项中的值相关:首先下拉,实现的方法太多.
最简单的方法是使用SQLdatasource之类的数据源,并使用智能标记,并使用从第一个下拉所选值或其他数据源(例如会话,路由等)中的参数向您的选择添加where子句状态,如下所示:
if you using data-binding on your page, and the sub category is related to the value from first drop down, there is too many way to implement.
easiest way is use a datasource like SQLdatasource, and use smart tag, and add a where clause state to your selection with a parameter from your first drop down selected value or other source like session,route,... like this:
<asp:SqlDataSource ID="SqlDataSource2" runat="server"

ConnectionString="<%


ConnectionStrings:testConnectionString SelectCommand =" > < SelectParameters > < asp:ControlParameter ControlID =" DefaultValue 1 " 名称 状态ID" 属性名称 =" 类型 =" Int32" ">/ >
ConnectionStrings:testConnectionString %>" SelectCommand="SELECT * FROM [orders] WHERE ([status_id] = @status_id)"> <SelectParameters> <asp:ControlParameter ControlID="ddl1" DefaultValue="1" Name="status_id" PropertyName="SelectedValue" Type="Int32" />



或者您可以将OnSelectedIndexChanged事件用于第一个数据绑定,请查看以下代码片段:



or you can use OnSelectedIndexChanged event for first databind, look at this code snipped:

protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var ds = (from a in DB.orders where status_id == ddl1.SelectedValue select a).ToList();
            ddl2.DataSource = ds;
        }


接下来是使用Linq DataSource并在选择事件时处理您的绑定逻辑,如下所示:


Next is use Linq DataSource and on selecting event handle your binding logic like this:

protected void linqds_Selecting(object sender, LinqDataSourceSelectEventArgs e)
        {
            e.Result = (from a in DB.orders where status_id == ddl1.SelectedValue select a).ToList();
        }



有一个下拉事件-onselectedindexchange.您可以使用此事件.在第一个下拉列表的选定索引更改上,将第一个下拉列表的值传递给您的加载方法,然后将结果填充到下一个下拉列表.

快乐编码:)
Hi,
There is one event for dropdown - onselectedindexchange. You can use this event. 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 :)


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

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