yqchamberlain
yqchamberlain
2014-11-13 04:53
采纳率: 50%
浏览 2.2k

asp.net 急求方法源码

制作一组联动的“学年-学期-分院-教师”的下拉列表。当最后选择教师后自动生成一个表格,这个怎么触发最后一个 DropDownList控件让table自动生成呢。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • ftz514396491
    Vincent_TT 2014-11-13 07:32
    已采纳


    教师1
    教师2
    教师3

    function test(){
    alert(444);
    }

    直接用onchange事件吧,这样在不更改教师的情况下减少了重新刷新table造成的性能消耗

    点赞 评论
  • joeyluo57
    joeyluo57 2014-11-24 07:59

    Aspx页面:

    <asp:DropDownList ID="ddlClass" runat="server" OnSelectedIndexChanged="ddlClass_SelectedIndexChanged" />
    <asp:DropDownList ID="ddlTeacher" runat="server" OnSelectedIndexChanged="ddlTeacher_SelectedIndexChanged" />
    

    后台Cs:
    public string[] arrayClass = { "Class1", "Class2", "Class3" };
    public string[] arrayTeachers1 = { "T1", "T2", "T3" };
    public string[] arrayTeachers2 = { "T4", "T5", "T6" };
    public string[] arrayTeachers3 = { "T7", "T8", "T9" };

            protected void Page_Load(object sender, EventArgs e)
            {
                if(!IsPostBack)
                {
                    ddlClass.DataSource = arrayClass;
                    ddlClass.DataBind();
                    ddlClass.SelectedIndex = 0;
    
                    ddlTeacher.DataSource = arrayTeachers1;
                    ddlTeacher.DataBind();
                }
            }
    
            protected void ddlClass_SelectedIndexChanged(object sender, EventArgs e)
            {
                switch(ddlClass.SelectedIndex)
                {
                    case 0:
                        ddlTeacher.DataSource = arrayTeachers1;
                        break;
                    case 1:
                        ddlTeacher.DataSource = arrayTeachers2;
                        break;
                    case 2:
                        ddlTeacher.DataSource = arrayTeachers3;
                        break;
                }
    
                ddlTeacher.DataBind();
            }
    
            protected void ddlTeacher_SelectedIndexChanged(object sender, EventArgs e)
            {
                if(ddlTeacher.SelectedValue.Equals("T1"))
                {
                    //生成Table
                }
            }
        }
    
    点赞 评论

相关推荐