2 yqchamberlain yqchamberlain 于 2014.11.13 12:53 提问

asp.net 急求方法源码
c#

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

2个回答

ftz514396491
ftz514396491   2014.11.13 15:32
已采纳


教师1
教师2
教师3

function test(){
alert(444);
}

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

joeyluo57
joeyluo57   2014.11.24 15: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
            }
        }
    }
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!