Asp.net selects and cancels all operations, and the deleted (ajax) after selection achieves no refreshing effect.

Source: Internet
Author: User

Front-end code The Code is as follows:
: <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> User Information Operation </title>
<Script language = "javascript" type = "text/javascript" src = "ajax/jquery. js"> </script>
<Script language = "javascript" type = "text/javascript">
// Page Initialization
$ (Document). ready (function () {loadUserInfo ();});
// Load user information to the page
Function loadUserInfo ()
{
$. Ajax (
{
Type: "POST ",
Url: "Default. aspx ",
Data: {action: 'action '},
Success: loadUserInfoCallbace
}
);
}
// Page initialization callback function
Function loadUserInfoCallbace (r)
{
If (r = "")
{
$ ("# UserInfo" ).html ("no data ");
}
Else
{
$ ("# UserInfo" pai.html (r );
}
}
// Select all
Function CheckAll (obj)
{
$ ("Input [@ type = checkbox] [@ name = checkItem]"). attr ("checked", $ (obj). attr ("checked "));
}
// Collect all selected items
Function NumberID ()
{
Var allcheckboxs = $ ("input [@ type = checkbox] [@ name = checkItem] [checked]");
Var ids = "";
For (I = 0; I <allcheckboxs. length; I ++)
{
Var id = $ (allcheckboxs [I]). attr ("id"). split ("_") [1];
Ids + = id;
Ids + = ",";
}
Return ids;
}
// Delete a user
Function DeleteUser ()
{
If (! Window. confirm ("Do you really want to delete the selected user information? "))
{
Return;
}
Var ids = NumberID ();
$. Ajax ({
Type: 'post ',
Url: 'default. aspx ',
Data: {action: 'delete', userid: ids },
Success: deleteUserCall
});
}
// Delete the user callback function
Function deleteUserCall (r)
{
If (r = "OK ")
{
Alert ("deleted successfully ");
LoadUserInfo ();
}
Else
{
Alert ("failed ");
}
}
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div style = "text-align: center" id = "userInfo">
</Div>
</Form>
</Body>
</Html>

Background code:
Copy codeThe Code is as follows:
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 ();
}
}
/// <Summary>
/// Zhou Xin loads user details on September 8
/// </Summary>
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 ("<table> <tr> <td> <input id = 'checkall' name = 'checkall' type = 'checkbox' onclick = 'checkall (this) '/> select all </td> <td> User Name </td> <td> full user name </td> </tr> ");
While (myda. Read ())
{
Str. Append ("<tr> <td> ");
Str. append ("<input id = 'checkitem _" + myda ["ID"]. toString () + "'Type = 'checkbox' name = 'checkitem 'style = 'text-align = 'left' onclick = 'numberid () '/> </td> ");
Str. Append ("<td>" + myda ["UserName"]. ToString () + "</td> ");
Str. Append ("<td>" + myda ["FullName"]. ToString () + "</td> </tr> ");
}
Str. Append ("</table> ");
Str. append ("<div style = 'text-align: Center'> <input type = 'button 'value = 'delete' onclick = 'deleteuser () '/> </div> ");
Response. Clear ();
Response. ContentType = "application/text ";
Response. Write (str );
Response. End ();
}
/// <Summary>
/// Zhou Xin 2009-6-8 Delete the details of the selected user
/// </Summary>
Public void DeleteUser ()
{
// Obtain the user ID
String strID = Request ["userid"];
String Userid = strID. Substring (0, strID. Length-1 );
// Convert to an array
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 ();
}
}
}

:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.