JQuery实现Repeater无刷新批量删除(附源码)

前台页面

<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();
}

Demo.js文件

$(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
})


})

 

源码下载

posted @ 2011-08-17 13:31  隆中小屋  阅读(3525)  评论(4编辑  收藏  举报