如何绑定其他下拉列表中的所有值 [英] how to get bind all the values in drop down depending upon the other drop down

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

问题描述



我想根据类别选择产品....我使用了两个下拉菜单,一个用于类别,一个用于产品....我想通过选择类别来选择产品...帮助我

Hi,

i want to select the products depending upon the categories....i used two drop downs one for category and one for products....i want to select the product by selecting the category...help me

推荐答案


DataClassesDataContext Db = new DataClassesDataContext();
   protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           var result = from x in Db.cates
                        select x;

           DropDownList1.DataSource = result;
           DropDownList1.DataTextField = "cate1";
           DropDownList1.DataValueField = "id";
           DropDownList1.DataBind();

           var resultItem = from x in Db.Items
                        select x;

           DropDownList2.DataSource = resultItem;
           DropDownList2.DataTextField = "Item_name";
           DropDownList2.DataValueField = "item_code";
           DropDownList2.DataBind();


       }



   }
   protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
   {
       var result = (from x in Db.Items
                    where x.item_code == Convert.ToInt32(DropDownList1.SelectedValue)
                    select x).Single();
//put here as much as u want to bind ddl but make sure u bind ddlist in Load first  then assign SelectedValue .

       DropDownList2.SelectedValue = result.item_code.ToString();

   }





<div>
      <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"

          onselectedindexchanged="DropDownList1_SelectedIndexChanged">
      </asp:DropDownList>
      <asp:DropDownList ID="DropDownList2" runat="server">
      </asp:DropDownList>

  </div>


最好的问候
M.Mitwalli


Best Regards
M.Mitwalli


@ Aparna

您可以为类别ddl
使用selectedindex更改的事件 在类别选择的索引更改事件上,您可以绑定产品

请参考

http://www.velocityreviews. com/forums/t89804-re-how-to-capture-selectedindexchanged-event-of-dropdownlist-in-datagrid.html [ http://stackoverflow.com/questions/1180863/asp-net- c-dropdownlist-selectedindexchanged-event-not-firing [ ^ ]

但不要忘记将您的autopostback = true属性保留在下拉列表中
希望对您有帮助
Hi @Aparna

you can use the selectedindex changed event for the category ddl
on category selected index changed event you can bind the product

Please Refer

http://www.velocityreviews.com/forums/t89804-re-how-to-capture-selectedindexchanged-event-of-dropdownlist-in-datagrid.html[^]

http://stackoverflow.com/questions/1180863/asp-net-c-dropdownlist-selectedindexchanged-event-not-firing[^]

But don''t forget to keep your autopostback=true prop of your Dropdown list
Hope it will help You


您可以像这样...

1)首先,您需要将类别下拉列表的AutoPostback 属性设置为true,并将一个selected index change event附加到类别下拉列表.

2)现在您只需要绑定Categories下拉列表即可.

3)然后在类别下拉菜单selected index change event中,您需要将您的产品dropdwon与这样的选择查询绑定...

从产品表中选择*,其中类别ID =您所选择的类别的值或文本;

因此这会根据类别下拉列表中的产品下拉列表中返回的过滤数据.
you can go like this...

1) First of all you need to set AutoPostback property of you category dropdown to true, and also attache one selected index change event to categorydropdown.

2) now all you need to bind only Categories dropdown.

3) then in you category dropdown selected index change event you need to bind your product dropdwon with select query like this...

select * from yourproducttable where category id = yourcategorydropdwon''s selected value or text;

so this will return your filtered data based on in your product dropdown based on category dropdown.


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

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