程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> ASP.NET基礎 >> asp.net兩級聯動(包含添加和修改)

asp.net兩級聯動(包含添加和修改)

編輯:ASP.NET基礎
<script language="javascript" type="text/javascript">
//科目數據初始化
var subcat = new Array();
subcat[0] = new Array('0', '請選擇科目', '0');
subcat[1] = new Array('x1', '語文', 'x1yw');
subcat[2] = new Array('x2', '語文', 'x2yw');
subcat[3] = new Array('x3', '語文', 'x3yw');
subcat[4] = new Array('x4', '語文', 'x4yw');
subcat[5] = new Array('x5', '語文', 'x5yw');
subcat[6] = new Array('x6', '語文', 'x6yw');
subcat[7] = new Array('c5', '語文', 'c5yw');
subcat[8] = new Array('c6', '語文', 'c6yw');
subcat[9] = new Array('c7', '語文', 'c7yw');
subcat[10] = new Array('g1', '語文', 'g1yw');
subcat[11] = new Array('g3', '語文', 'g3yw');
subcat[12] = new Array('g4', '語文', 'g4yw');
subcat[13] = new Array('x1', '數學', 'x1sx');
subcat[14] = new Array('x2', '數學', 'x2sx');
subcat[15] = new Array('x3', '數學', 'x3sx');
subcat[16] = new Array('x4', '數學', 'x4sx');
subcat[17] = new Array('x5', '數學', 'x5sx');
subcat[18] = new Array('x6', '數學', 'x6sx');
subcat[19] = new Array('c5', '數學', 'c5sx');
subcat[20] = new Array('c6', '數學', 'c6sx');
subcat[21] = new Array('c7', '數學', 'c7sx');
subcat[22] = new Array('g1', '數學', 'g1sx');
subcat[23] = new Array('g3', '數學', 'g3sx');
subcat[24] = new Array('g4', '數學', 'g4sx');
subcat[25] = new Array('x1', '英語', 'x1yy');
subcat[26] = new Array('x2', '英語', 'x2yy');
subcat[27] = new Array('x3', '英語', 'x3yy');
subcat[28] = new Array('x4', '英語', 'x4yy');
subcat[29] = new Array('x5', '英語', 'x5yy');
subcat[30] = new Array('x6', '英語', 'x6yy');
subcat[31] = new Array('c5', '英語', 'c5yy');
subcat[32] = new Array('c6', '英語', 'c6yy');
subcat[33] = new Array('c7', '英語', 'c7yy');
subcat[34] = new Array('g1', '英語', 'g1yy');
subcat[35] = new Array('g3', '英語', 'g3yy');
subcat[36] = new Array('g4', '英語', 'g4yy');
subcat[37] = new Array('c5', '物理', 'c5wl');
subcat[38] = new Array('c6', '物理', 'c6wl');
subcat[39] = new Array('c7', '物理', 'c7wl');
subcat[40] = new Array('g1', '物理', 'g1wl');
subcat[41] = new Array('g3', '物理', 'g3wl');
subcat[42] = new Array('g4', '物理', 'g4wl');
subcat[43] = new Array('c5', '化學', 'c5hx');
subcat[44] = new Array('c6', '化學', 'c6hx');
subcat[45] = new Array('c7', '化學', 'c7hx');
subcat[46] = new Array('g1', '化學', 'g1hx');
subcat[47] = new Array('g3', '化學', 'g3hx');
subcat[48] = new Array('g4', '化學', 'g4hx');
subcat[49] = new Array('c5', '政治', 'c5zz');
subcat[50] = new Array('c6', '政治', 'c6zz');
subcat[51] = new Array('c7', '政治', 'c7zz');
subcat[52] = new Array('g1', '政治', 'g1zz');
subcat[53] = new Array('g3', '政治', 'g3zz');
subcat[54] = new Array('g4', '政治', 'g4zz');
subcat[55] = new Array('c5', '歷史', 'c5ls');
subcat[56] = new Array('c6', '歷史', 'c6ls');
subcat[57] = new Array('c7', '歷史', 'c7ls');
subcat[58] = new Array('g1', '歷史', 'g1ls');
subcat[59] = new Array('g3', '歷史', 'g3ls');
subcat[60] = new Array('g4', '歷史', 'g4ls');
subcat[61] = new Array('c5', '生物', 'c5sw');
subcat[62] = new Array('c6', '生物', 'c6sw');
subcat[63] = new Array('c7', '生物', 'c7sw');
subcat[64] = new Array('g1', '生物', 'g1sw');
subcat[65] = new Array('g3', '生物', 'g3sw');
subcat[66] = new Array('g4', '生物', 'g4sw');
subcat[67] = new Array('c5', '地理', 'c5dl');
subcat[68] = new Array('c6', '地理', 'c6dl');
subcat[69] = new Array('c7', '地理', 'c7dl');
subcat[70] = new Array('g1', '地理', 'g1dl');
subcat[71] = new Array('g3', '地理', 'g3dl');
subcat[72] = new Array('g4', '地理', 'g4dl');
subcat[73] = new Array('x1', '其它', 'x1qt');
subcat[74] = new Array('x2', '其它', 'x2qt');
subcat[75] = new Array('x3', '其它', 'x3qt');
subcat[76] = new Array('x4', '其它', 'x4qt');
subcat[77] = new Array('x5', '其它', 'x5qt');
subcat[78] = new Array('x6', '其它', 'x6qt');
subcat[79] = new Array('c5', '其它', 'c5qt');
subcat[80] = new Array('c6', '其它', 'c6qt');
subcat[81] = new Array('c7', '其它', 'c7qt');
subcat[82] = new Array('g1', '其它', 'g1qt');
subcat[83] = new Array('g3', '其它', 'g3qt');
subcat[84] = new Array('g4', '其它', 'g4qt');
//選擇年級
function ChangeGrade(obj,id)
{
var oObj = document.getElementById(id);
oObj.length = 0;
for(i=0; i<subcat.length; i++)
{
if(subcat[i][0] == obj)
{
oObj.options[oObj.length] = new Option(subcat[i][1], subcat[i][2]);
}
}
}
//修改頁面科目數據加載
function LoadingCourse()
{
var SubjectSelect = "<%=SubjectSelect %>";
var GradeSelect = "<%=GradeSelect %>";
if(SubjectSelect != "")
{
LoadingSubject(GradeSelect, 'Course', SubjectSelect);
}
}
function LoadingSubject(obj,id, sid)
{
var slt = document.forms[0].elements["id"];
var oObj = document.getElementById(id);
oObj.length = 0;
oObj.options[0] = new Option('全部科目', '0');
for(i=0; i<subcat.length; i++)
{
if(subcat[i][0] == obj)
{
oObj.options[oObj.length] = new Option(subcat[i][1], subcat[i][2]);
if(subcat[i][2] == sid)
{
oObj.options[oObj.length-1].selected = true;
}
}
}
}
</script>
<body onload="LoadingCourse();">
<select name="Grade" id="Grade" class="input" onchange="ChangeGrade(this.value,'Course')">
<option value="0">請選擇年級</option>
<option value="x1" <%=GradeSelect == "x1" ? "selected":"" %>>一年級</option>
<option value="x2" <%=GradeSelect == "x2" ? "selected":"" %>>二年級</option>
<option value="x3" <%=GradeSelect == "x3" ? "selected":"" %>>三年級</option>
<option value="x4" <%=GradeSelect == "x4" ? "selected":"" %>>四年級</option>
<option value="x5" <%=GradeSelect == "x5" ? "selected":"" %>>五年級</option>
<option value="x6" <%=GradeSelect == "x6" ? "selected":"" %>>六年級</option>
<option value="c5" <%=GradeSelect == "c5" ? "selected":"" %>>七年級</option>
<option value="c6" <%=GradeSelect == "c6" ? "selected":"" %>>八年級</option>
<option value="c7" <%=GradeSelect == "c7" ? "selected":"" %>>九年級</option>
<option value="g1" <%=GradeSelect == "g1" ? "selected":"" %>>高一</option>
<option value="g3" <%=GradeSelect == "g3" ? "selected":"" %>>高二</option>
<option value="g4" <%=GradeSelect == "g4" ? "selected":"" %>>高三</option>
</select>
<select name="Course" id="Course" class="input">
<option value="0">請選擇年級</option>
</select>
</body>
//C#代碼
protected void Page_Load(object sender, System.EventArgs e)
{
public string GradeSelect = String.Empty;
public string SubjectSelect = String.Empty;
if (!(IsPostBack))
{
GradeSelect = Request.QueryString["Grade"];
SubjectSelect = Request.QueryString["Course"];
}
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved