asp.Netgridviewマルチページ時の一括削除
4290 ワード
book_admin.aspx
book_admin.aspx.cs
book_admin.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.OleDb;
public partial class admin_book_admin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//
admin.checkadmin();
btnDel.Attributes.Add("onclick", "return confirm(' ?')");
if (!Page.IsPostBack)
{
datainit();
}
}
protected void grwBook_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.grwBook.PageIndex = e.NewPageIndex;
Session["curretnPage"] = e.NewPageIndex;
datainit();
}
//
private void datainit()
{
DataSet ds = db.dataSet("select ID,UserName,Comments,Postdate,newsid from Feedback order by Postdate desc,newsid desc");
if (ViewState["currentPage"] != null)
{
this.grwBook.PageIndex = Convert.ToInt32(Session["currentPage"]);
}
this.grwBook.DataSource = ds;
this.grwBook.DataBind();
}
//
protected void btnDel_Click(object sender, EventArgs e)
{
string sqlText = "(";
for (int i = 0; i {
// n 3
CheckBox cbx = (CheckBox)grwBook.Rows[i].FindControl("cbxId");
if (cbx.Checked == true)
{
sqlText = sqlText + Convert.ToInt32(grwBook.DataKeys[i].Value) + ",";
}
}
//
if (sqlText != "(")
{
// ,
sqlText = sqlText.Substring(0, sqlText.Length - 1) + ")";
sqlText = "delete from Feedback where ID in" + sqlText;
try
{
//
db.excuteSql(sqlText);
//
common.salert(" ");
datainit();
//Response.Redirect("book_admin.aspx");
}
catch (Exception ex)
{
// ,
common.salert(ex.Message);
}
finally
{
}
}
else
{
common.salert(" ");
}
}
}