JQuery实现Repeater无刷新批量删除(附后台asp.net源码)
<head runat="server">
<title>无标题页</title>
<script src="Js/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="Js/Demo.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="content">
<table>
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<tr>
<td>
<input type="checkbox">
</td>
<td>
学生ID
</td>
<td>
学生姓名
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<input type="checkbox">
</td>
<td style="text-align: center">
<%#Eval("studentId") %>
</td>
<td style="text-align: center">
<%#Eval("name") %>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</div>
<div>
<input id="btnDel" type="button" value="删除"></input>
</div>
</form>
</body>
protected void Page_Load(object sender, EventArgs e)
{
StudentBll _bll = new StudentBll();
if (Request.QueryString["id"]!=""&&Request.QueryString["id"]!=null)
{
string _ids = Request.QueryString["id"];
_bll.Delete(_ids);
}
Repeater1.DataSource = _bll.SelectALL();
Repeater1.DataBind();
}
$(function() {
// 此函数是去掉javascript中字符串的开头和结尾的空格和换行
function Trim(str)
{
var statrIndex;
var endIndes;
for(i=0;i<str.length;i++)
{
var k=str.charAt(i);
if (k!="\n"&&k!=" ")
{
statrIndex=i; break;
}
}
for (i=str.length-1;i<str.length;i--)
{
var k=str.charAt(i);
if (k!="\n"&&k!=" ")
{
endIndes=i; break;
}
}
return str.substring(statrIndex,endIndes+1);
};
$("#btnDel").click(function(){
var ids="''";
$("#content input:checked").parent().next().each(function(i){
ids=ids+",'"+Trim($(this).text())+"'";
});
$("#content").load("Default.aspx?id="+encodeURI(ids)+"#p-Getting-Started #content") //局部更新Repeater
})
})
源码下载