作者taotu (透抽)
看板Web_Design
标题[问题] asp.net dropdownlist控制项问题
时间Thu Nov 17 11:50:37 2005
http://corpus.iecs.fcu.edu.tw/new/taotu/exercise3.aspx
关於删除的功能
本是想由下拉是选单所选取的名字
但是不知道为何
button触动之後
抓不到dropdownlist选取的项目
只会一直抓第一个项目
请情指点一下
以下为原始码
//GetDB和SetDB是自己写用来存取资料库用的
void Page_Load(){
OleDbDataReader dr=GetDB("SELECT TeacherName FROM TEACHER");//读取资料库
ArrayList teacherList=new ArrayList();
while(dr.Read()==true){
teacherList.Add(dr["TeacherName"]);
}//将资料放入阵列中
ddlTeacherList.DataSource=teacherList;//将阵列放录下拉是选单
ddlTeacherList.DataBind();//不太清楚处其作用
DataGrid1.DataSource=GetDB("SELECT * FROM TEACHER");//画出表格
DataGrid1.DataBind();
}
void InsertTeacher(Object sensder,EventArgs e){
String str="INSERT INTO TEACHER(TeacherID,TeacherName) VALUES('"+tbxTeacherID.Text+"','"+tbxTeacherName.Text+"')";
SetDB(str);
Page_Load();
}
void DeleteTeacher(Object sensder,EventArgs e){
String str="DELETE FROM TEACHER WHERE TeacherName='"+ddlTeacherList.SelectedValue+"'";
//SetDB(str);
Response.Write(ddlTeacherList.SelectedItem.Value);//
//因为此问题删除功能暂用印出表示
}
</script>
<html>
<head>
<title>Exercise3</title>
</head>
<body>
<form runat="server">
<br />
ID<asp:textbox id="tbxTeacherID" runat="server"/>
Name<asp:textbox id="tbxTeacherName" runat="server"/>
<asp:button id="btnInsertTeacher" runat="server" text="新增老师" Onclick="InsertTeacher" />
<br />
老师:
<asp:dropdownlist id="ddlTeacherList" runat="server"/>
<asp:button id="btnDeleteTeacher" runat="server" text="删除老师" Onclick="DeleteTeacher" />
<br />
<asp:DataGrid id="DataGrid1" runat="server" />
<br />
</form>
</body>
</htnl>
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.134.242.171