Repeater Selects all deletion and paging Implementation ideas and code

Source: Internet
Author: User

Copy codeThe Code is as follows: <script type = "text/javascript">
Function SelectAll (box)
{
For (var I = 0; I <document. form1.elements. length; I ++)
{
Var e = document. form1.elements [I];
If (e. type = 'checkbox '))
{
Var o = e. name. lastIndexOf ('cbx ');
If (o! =-1)
{
E. checked = box. checked;
}
}
}
}
</Script>
<Body>
<Form id = "form1" runat = "server">
<Div>
</Div>
<Asp: Repeater ID = "Repeater1" runat = "server">
<HeaderTemplate>
<Table>
<Tr> <th> <input id = "chkHeader" type = "checkbox" onclick = "SelectAll (this) "/> select all </th> <th> Registration number </th> <th> Student ID number </th> <th> name </th> <th> ID number </ th> <th> residential address </th> <th> Category </th> <th> professional </th> </tr>
</HeaderTemplate>
<ItemTemplate>
<Tr> <td align = "center"> <asp: CheckBox ID = "cbx" runat = "server"/> </td> <asp: label id = "lbl" Text = '<% # Eval ("id") %> 'runat = "server"> </asp: label> </td> <% # Eval ("ksh") %> </td> <% # Eval ("xm ") %> </td> <% # Eval ("sfzh") %> </td> <% # Eval ("jtdz ") %> </td> <% # Eval ("jhxzmc") %> </td> <% # Eval ("lqzy ") %> </td> </tr>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</Asp: Repeater>
<Br/>
<Asp: Button ID = "btnDel" runat = "server" onclick = "btnDel_Click" Text = "batch Delete" OnClientClick = "return confirm ('Are you sure you want to delete it? This operation cannot be recovered !!! ') "/>
<Br/>
<Br/>
<Webdiyer: AspNetPager ID = "benren" runat = "server" pagesize = "2"
CssClass = "anpager" onpagechanged = "aspnetpager?pagechanged"
FirstPageText = "Homepage" LastPageText = "last page" NextPageText = "next page" PrevPageText = "Previous Page"
ShowMoreButtons = "False" ShowPageIndexBox = "Never" AlwaysShow = "True">
</Webdiyer: AspNetPager>
</Form>
</Body>
============================
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
String username = Session ["username"]. ToString ();
SqlConnection conn = new SqlConnection (ConfigurationManager. ConnectionStrings ["shan"]. ConnectionString );
Conn. Open ();
SqlCommand count = new SqlCommand ("select count (*) from do. so where baosongren = '" + username + "'", conn );
Benren. RecordCount = (int) count. ExecuteScalar ();
Conn. Close ();
BindData ();
}
}
Public void BindData ()
{
String username = Session ["username"]. ToString ();
SqlConnection conn = new SqlConnection (ConfigurationManager. ConnectionStrings ["shnn"]. ConnectionString );
String SQL = "select * from dao where baosongren = '" + username + "'order by ID desc"; // This statement should be used in large data: select top query statement
SqlDataAdapter da = new SqlDataAdapter (SQL, conn );
DataSet ds = new DataSet ();
Da. Fill (ds, benren. PageSize * (benren. CurrentPageIndex-1), benren. PageSize, "temptbl ");
DataTable dt = ds. Tables ["temptbl"];
Repeater1.DataSource = dt;
Repeater1.DataBind ();
}
Protected void AspNetPager1_PageChanged (object src, EventArgs e)
{
// AspNetPager1.CurrentPageIndex = e. NewPageIndex;
BindData ();
}
Protected void btnDel_Click (object sender, EventArgs e)
{
String delId = "";
// Traverse to obtain the selected item first
For (int I = 0; I <this. Repeater1.Items. Count; I ++)
{
CheckBox cbx = (CheckBox) Repeater1.Items [I]. FindControl ("cbx ");
Label lbl = (Label) Repeater1.Items [I]. FindControl ("lbl ");
If (cbx! = Null)
{
If (cbx. Checked)
{
DelId + = lbl. Text + ",";
}
}
}
// Remove the last one,
DelId = (delId + ")"). Replace (",)","");
// Response. Write ("the delete statement is: delete news_sosuo8 _ where id_news _ in (" + delId + ")");
// Write the deletion Statement by yourself.
SqlConnection conn = new SqlConnection (ConfigurationManager. ConnectionStrings ["shann"]. ConnectionString );
SqlCommand del = new SqlCommand ("delete so where id in (" + delId + ")", conn );
Conn. Open ();
Int myupdate = del. ExecuteNonQuery ();
Conn. Close ();
If (myupdate> 0)
{
Page. ClientScript. RegisterStartupScript (Page. GetType (), "message", "<script language = 'javascript '> alert ('deleted successfully! '); </Script> ");
}
BindData ();
}

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.