如何处理在C#中更改的组合框selectedIndex [英] how to handle combobox selectedindexchanged in c#

查看:224
本文介绍了如何处理在C#中更改的组合框selectedIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组合框,上面有鲜花,水果,蔬菜
当我在combobox2中选择combobox1时,它必须显示水果的类型(苹果,芒果,橙色).所有这些必须动态完成,这意味着从sql s erver

i have one combobox with flowers,fruits,vegetables
when i select combobox1 in combobox2 it has to display types of fruits(apple,mango,orange)..all this has to be done dynamically means getting the values from sql server

推荐答案

,您可以使用存储过程来解决此问题,该过程将根据您从组合框中选择的组提供所有数据,然后在前端,您可以在Windows或Windows上的选择索引更改事件中调用该方法可以使用Web应用程序将自动回发属性设置为true.
you can solve this using a store proc which will provide all data according to group you choose from combo box and then on front end you can call that method on select index change event on windows or can set auto post back property to true if using web application.


只需将事件名称添加到" onselectedindexchanged "组合框的属性中,如下所示:
onselectedindexchanged ="ddlEmpName_SelectedIndexChanged"

并在事件代码后面添加事件处理程序,如下所示:

Just add the event name to "onselectedindexchanged"property of Combobox as :
onselectedindexchanged="ddlEmpName_SelectedIndexChanged"

and add an event handler to code behind like this:

protected void ddlEmpName_SelectedIndexChanged(object sender, EventArgs e)
      {
       
           // Your code here to fetch and assign data from database.

      }




快乐编码:)




Happy Coding :)


简单在Combobox1触发事件中,您只需调用fill方法即可从db中检索数据并绑定到Combobox2中.
在Combobox1中执行AutoPostBack ="True"
像Ex:-
Simple In side the Combobox1 fire event you just call a fill method which will retrive data from db and bind in Combobox2.
In Combobox1 do AutoPostBack="True"
like Ex:-
protected void Combobox1_SelectedIndexChanged(object sender, EventArgs e)

    {
        FillMethod(Combobox1.SelectedValue);
    }


公共无效FillMethod(int CategoryId)
{
//从db中获取数据,其中id = CategoryId
//将数据绑定到Combobox2
}


public void FillMethod(int CategoryId)
{
//Fetch data from db where id=CategoryId
//Bind data into Combobox2
}


这篇关于如何处理在C#中更改的组合框selectedIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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