public partial class admin_book_admin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//判斷管理員是否已經(jīng)登陸
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();
}
//數(shù)據(jù)綁定
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();
}
//執(zhí)行刪除操作
protected void btnDel_Click(object sender, EventArgs e)
{
string sqlText = "(";
for (int i = 0; i < grwBook.Rows.Count; 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 != "(")
{
//去掉最后的逗號(hào),并且加上右括號(hào)
sqlText = sqlText.Substring(0, sqlText.Length - 1) + ")";
sqlText = "delete from Feedback where ID in" + sqlText;
try
{
//執(zhí)行刪除語(yǔ)句
db.excuteSql(sqlText);
//重新綁定數(shù)據(jù)
common.salert("刪除成功");
datainit();
//Response.Redirect("book_admin.aspx");
}
catch (Exception ex)
{
//若有錯(cuò)誤發(fā)生,輸出錯(cuò)誤信息
common.salert(ex.Message);
}
finally
{
}
}
else
{
common.salert("您還沒(méi)有選中有刪除的項(xiàng)");
}
}
}
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com