.net ajax批量删除,asp.net 全部选中与取消操作,选中后的删除(ajax)实现无刷新效果...
前臺代碼
:
用戶信息操作//頁面的初始化
$(document).ready( function(){ loadUserInfo(); });
//加載用戶信息到頁面
function loadUserInfo()
{
$.ajax(
{
type:"POST",
url:"Default.aspx",
data:{action:'action'},
success:loadUserInfoCallbace
}
);
}
//頁面初始化回調(diào)函數(shù)
function loadUserInfoCallbace(r)
{
if(r=="")
{
$("#userInfo").html("暫無數(shù)據(jù)");
}
else
{
$("#userInfo").html(r);
}
}
//全部選中
function CheckAll(obj)
{
$("input[@type=checkbox][@name=checkItem]").attr("checked",$(obj).attr("checked"));
}
//收集所有選中項
function NumberID()
{
var allcheckboxs=$("input[@type=checkbox][@name=checkItem][checked]");
var ids="";
for(i=0;i
{
var id=$(allcheckboxs[i]).attr("id").split("_")[1];
ids+=id;
ids+=",";
}
return ids;
}
//刪除用戶
function DeleteUser()
{
if(!window.confirm("您真的要刪除選中用戶信息嗎?"))
{
return;
}
var ids=NumberID();
$.ajax({
type:'POST',
url:'Default.aspx',
data:{action:'Delete',userid:ids},
success:deleteUserCall
});
}
//刪除用戶回調(diào)函數(shù)
function deleteUserCall(r)
{
if(r=="ok")
{
alert("刪除成功");
loadUserInfo();
}
else
{
alert("失敗");
}
}
后臺代碼:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
string Straction = "";
protected void Page_Load(object sender, EventArgs e)
{
Straction = Request["action"];
if(Straction=="action")
{
UserInfo();
}
if (Straction == "Delete")
{
DeleteUser();
}
}
///
/// 周昕 2009-6-8號加載用戶詳細信息
///
public void UserInfo()
{
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = ConfigurationManager.ConnectionStrings["BoBoConn"].ToString();
string sql = "select * from loginuser";
SqlCommand mycom = new SqlCommand(sql, mycon);
mycon.Open();
SqlDataReader myda = mycom.ExecuteReader();
StringBuilder str = new StringBuilder();
str.Append("
| 全選 | 用戶名 | 用戶全名 |
while (myda.Read())
{
str.Append("
");str.Append("
");str.Append("
" + myda["UserName"].ToString() + "");str.Append("
" + myda["FullName"].ToString() + "");}
str.Append("
");str.Append("
Response.Clear();
Response.ContentType = "application/text";
Response.Write(str);
Response.End();
}
///
/// 周昕 2009-6-8 刪除選中用戶的詳細信息
///
public void DeleteUser()
{
//獲取用戶ID
string strID = Request["userid"];
string Userid = strID.Substring(0, strID.Length - 1);
//轉(zhuǎn)換成為數(shù)組
string[] stridArray = Userid.Trim().Split(',');
string sql = "delete from loginuser where ID='" + stridArray[0].ToString() + "'";
for (int i = 0; i < stridArray.Length; i++)
{
string id = stridArray[i].ToString();
sql += "or ID='" + id + "'";
}
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = ConfigurationManager.ConnectionStrings["BoBoConn"].ToString();
mycon.Open();
SqlCommand mycom = new SqlCommand(sql, mycon);
int n = (int)mycom.ExecuteNonQuery();
mycon.Close();
if (n > 0)
{
Response.Clear();
Response.ContentType = "application/text";
Response.Write("ok");
Response.End();
}
else
{
Response.Clear();
Response.ContentType = "application/text";
Response.Write("no");
Response.End();
}
}
}
總結
以上是生活随笔為你收集整理的.net ajax批量删除,asp.net 全部选中与取消操作,选中后的删除(ajax)实现无刷新效果...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 原生 ajax查询,原生ajax啦啦啦
- 下一篇: Python识别表格图_使用Python