每次更改所选索引时,如何使用DropDown_SelectedIndexChanged事件 [英] How to work with DropDown_SelectedIndexChanged Event for every time when the selected index is change

查看:91
本文介绍了每次更改所选索引时,如何使用DropDown_SelectedIndexChanged事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码:

My Code:

SqlDBAccess db = new SqlDBAccess();
        protected void drpFaculty_SelectedIndexChanged(object sender, EventArgs e)
        {
            drpAdvisiorName.Items.Clear();
            drpAdvisiorName.Items.Add("<<Select Supervisor Name>>");
            try
            {
                db.Adapter("select TeacherName from tblTeacherAndDepartment where Department = '"+drpFaculty.SelectedItem.Text.ToString()+"'","teacherName");
                //lblerror.Text = drpFaculty.SelectedItem.Text.ToString();
                
                for (int i = 0; i < db.dataSet.Tables["teacherName"].Rows.Count; i++)
                {
                    //RadioButtonList1.Items.Add(db.dataSet.Tables["teacherName"].Rows[i][0].ToString());
                    drpAdvisiorName.Items.Add(db.dataSet.Tables["teacherName"].Rows[i][0].ToString());
                    //.Items.Add(db.dataSet.Tables["teacherName"].Rows[i][0].ToString());
                }

                db.dataSet.Tables["teacherName"].Clear();
            }
            catch (Exception ex)
            {
                lblerror.Text = ex.Message.ToString();
            }
        }



我的ASP.NET代码:


My ASP.NET Code:

<asp:DropDownList ID="drpFaculty" runat="server"

                   style="top: 83px; left: 240px; position: absolute; height: 26px; width: 473px"
                   AutoPostBack="True" onselectedindexchanged="drpFaculty_SelectedIndexChanged">
                   <asp:ListItem>Agricultural Engineering and Technology</asp:ListItem>
                   <asp:ListItem>Veterinary Science</asp:ListItem>
                   <asp:ListItem>Agriculture</asp:ListItem>
                   <asp:ListItem>Animal Husbandry</asp:ListItem>
                   <asp:ListItem>Agricultural Economics & Rural Sociology</asp:ListItem>
                   <asp:ListItem>Fisheries</asp:ListItem>
                   <asp:ListItem>Social Science</asp:ListItem>
                   <asp:ListItem>Nutrition and Food Science</asp:ListItem>
                   <asp:ListItem>BAM</asp:ListItem>
                   <asp:ListItem>ANSVM</asp:ListItem>
                   <asp:ListItem>Arts and Humanities</asp:ListItem>
                   <asp:ListItem>Biological Science</asp:ListItem>
                   <asp:ListItem>LAW</asp:ListItem>
                   <asp:ListItem>Electrical and Computer Engineering</asp:ListItem>
                   <asp:ListItem>Mechanical</asp:ListItem>
                   <asp:ListItem>Civil Engineering</asp:ListItem>
                   <asp:ListItem>Science</asp:ListItem>
               </asp:DropDownList>





我的问题:

当我换了dropdownlist项目的值是在另一个dropdownli中添加的值st只是第一次。但是,当我第二次更改时,第二个下拉列表的值不会改变。为什么会这样?事件是第一次被解雇了吗?或者我使用ScriptPanale因此为什么会出现问题。请检查我。

谢谢....



My Problem:
When I am changing in the dropdownlist items than the value is adding in another dropdownlist only 1st-time. but, when I am changing second time the value of second dropdownlist is not changing. Why this is ? Is the event fired only 1st time? Or I am using ScriptPanale thus why the problem. Please check me out.
Thank you....

推荐答案

为什么这行?



db.dataSet.Tables [teacherName]。清除();
Why this line?

db.dataSet.Tables["teacherName"].Clear();


这篇关于每次更改所选索引时,如何使用DropDown_SelectedIndexChanged事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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