<%@ page title="" language="c#" masterpagefile="~/manager.master" codebehind="managersendmessage.aspx.cs" inherits="teacherfiles.managersendmessage" enableeventvalidation="false"%>
<asp:content id="content1" contentplaceholderid="head" runat="server">
</asp:content>
<asp:content id="content2" contentplaceholderid="contentplaceholdercontent" runat="server">
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var lstboxallteachersid = "#"+'<%=lstboxallteachers.clientid%>';
var lstboxselectdteachersid="#"+'<%=lstboxselectdteachers.clientid%>';
var imabtnsendmessageid="#"+'<%=imabtnsendmessage.clientid%>';
var hiddenfileid="#"+'<%=hiddenfield1.clientid%>';
$('fieldset ul li img').click(function(){
var options;
var remove;
// 把选择项追加给对方
if($(this).attr("alt")=="arrowadd")
{
options= $(lstboxallteachersid+" option:selected");
remove=options.remove();
remove.appendto(lstboxselectdteachersid);
}
// 把选择项退回给对方
if($(this).attr("alt")=="arrowdelete")
options=$(lstboxselectdteachersid+" option:selected");
remove.appendto(lstboxallteachersid);
// 把全部追加给对方
if($(this).attr("alt")=="selectall")
options=$(lstboxallteachersid+' option');
// 把全部项退回给对方
if($(this).attr("alt")=="reset")
options=$(lstboxselectdteachersid+' option');
}
});
// 获取教师工号
function getseletedteachernum()
{
var lststaffs = document.getelementbyid('<%=lstboxselectdteachers.clientid%>');
var strstaffs = "";
for (var i = 0; i < lststaffs.options.length; i++) {
strstaffs +=lststaffs.options[i].value+",";
$(hiddenfileid).val(strstaffs);
}
// 当点击发送按钮
$(imabtnsendmessageid).click(function(){
getseletedteachernum()
});
</script>
<form>
<fieldset class="fieldset">
<legend class="legend">选择需要得到通知的教师</legend>
<ul>
<li>
<span>
<asp:listbox id="lstboxallteachers" runat="server"
cssclass="listbox"></asp:listbox>
</span>
<img src="images/arrowadd.jpg" alt="arrowadd" class="imagarrowadd" />
<img src="images/arrowdelete.jpg" alt="arrowdelete" class="imagarrowdelete" />
<span><asp:listbox id="lstboxselectdteachers" runat="server"
cssclass="listbox"></asp:listbox></span>
<asp:hiddenfield id="hiddenfield1" runat="server"/>
</li>
<img src="images/selectall.jpg" alt="selectall" />
<img src="images/reset.jpg" alt="reset" />
</ul>
</fieldset>
<br />
<legend class="legend">需要发送的消息</legend>
<asp:textbox id="txtcontent" runat="server" textmode="multiline" width="380px"
height="180px" cssclass="txtbox"></asp:textbox>
<span>
<asp:imagebutton id="imabtnsendmessage" runat="server"
imageurl="~/images/sendmessage.jpg" onclick="imabtnsendmessage_click"/>
<asp:imagebutton id="imagbtnresetcontent" runat="server"
imageurl="~/images/reset.jpg" onclick="imagbtnresetcontenet_click"/>
后台
public partial class managersendmessage : basepage
{
iteacher newiteacher = new teacherservice();
protected void page_load(object sender, eventargs e)
{
if (!ispostback)
bindlistboxallteachers();
}
}
public void bindlistboxallteachers()
this.lstboxallteachers.datasource = newiteacher.readallteacher();
this.lstboxallteachers.datatextfield = "teachername";
this.lstboxallteachers.datavaluefield = "teachernum";
this.lstboxallteachers.databind();
list<string> allselectedteahcernum = new list<string>();
// 得到选择的教师工号
public void sendselectedteahcermessage(string[] singlenums)
for (int i = 0; i < singlenums.count()-1; i++)
newiteacher.insertreceivemessage(singlenums[i].tostring(), this.txtcontent.text);
pageextension.alert(this, "发布成功!");
// 发送通知消息给选定的教师,
protected void imabtnsendmessage_click(object sender, imageclickeventargs e)
string allthenum = this.hiddenfield1.value;
string[] singlenums = allthenum.split(',');
sendselectedteahcermessage(singlenums);
// 重置发送内容
protected void imagbtnresetcontenet_click(object sender, imageclickeventargs e)
this.txtcontent.text = "";
}