过去的习惯,决定今天的你,所以,过去的懒惰,决定你今天的一败涂地。人来到这世界后,命运注定了他必须要拼搏,奋斗,坚持,勇敢地走下去,走出属于自己的道路,没有人能不劳而获。
book_admin.aspx
<asp:GridViewID="grwBook"runat="server"CellPadding="4"ForeColor="#333333"GridLines="None"AutoGenerateColumns="false"AllowPaging="true"DataKeyNames="ID"OnPageIndexChanging="grwBook_PageIndexChanging"PageSize="12">
<FooterStyleBackColor="#507CD1"Font-Bold="True"ForeColor="White"/>
<RowStyleBackColor="#EFF3FB"/>
<EditRowStyleBackColor="#2461BF"/>
<SelectedRowStyleBackColor="#D1DDF1"Font-Bold="True"ForeColor="#333333"/>
<PagerStyleBackColor="#2461BF"ForeColor="White"HorizontalAlign="Center"/>
<HeaderStyleBackColor="#507CD1"Font-Bold="True"ForeColor="White"/>
<AlternatingRowStyleBackColor="White"/>
<Columns>
<asp:BoundFieldDataField="ID"HeaderText="ID"/>
<asp:BoundFieldDataField="UserName"HeaderText="姓名">
<ItemStyleWidth="60px"/>
</asp:BoundField>
<asp:BoundFieldDataField="Comments"HeaderText="评论">
<ItemStylewidth="500px"/>
</asp:BoundField>
<asp:BoundFieldDataField="Postdate"HeaderText="日期"/>
<asp:HyperLinkFieldDataNavigateUrlFields="newsid"DataNavigateUrlFormatString="../news_zi.asp?id={0}"HeaderText="文章"DataTextField="newsid"target="_blank"/>
<asp:TemplateFieldHeaderText="操作">
<ItemTemplate>
<asp:CheckBoxrunat="Server"ID="cbxId"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerSettingsMode="NextPreviousFirstLast"FirstPageText="第一页"LastPageText="末页"NextPageText="下一页"PreviousPageText="上一页"/>
</asp:GridView>
book_admin.aspx.cs
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingSystem.Data.OleDb; publicpartialclassadmin_book_admin:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
//判断管理员是否已经登陆
admin.checkadmin(); btnDel.Attributes.Add("onclick","returnconfirm('确定删除吗?')"); if(!Page.IsPostBack)
{
datainit();
}
} protectedvoidgrwBook_PageIndexChanging(objectsender,GridViewPageEventArgse)
{
this.grwBook.PageIndex=e.NewPageIndex;
Session["curretnPage"]=e.NewPageIndex;
datainit();
} //数据绑定
privatevoiddatainit()
{
DataSetds=db.dataSet("selectID,UserName,Comments,Postdate,newsidfromFeedbackorderbyPostdatedesc,newsiddesc");
if(ViewState["currentPage"]!=null)
{
this.grwBook.PageIndex=Convert.ToInt32(Session["currentPage"]);
}
this.grwBook.DataSource=ds;
this.grwBook.DataBind(); } //执行删除操作
protectedvoidbtnDel_Click(objectsender,EventArgse)
{
stringsqlText="(";
for(inti=0;i<grwBook.Rows.Count;i++)
{
//搜索第n行3列
CheckBoxcbx=(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="deletefromFeedbackwhereIDin"+sqlText;
try
{
//执行删除语句
db.excuteSql(sqlText);
//重新绑定数据
common.salert("删除成功");
datainit();
//Response.Redirect("book_admin.aspx");
}
catch(Exceptionex)
{
//若有错误发生,输出错误信息
common.salert(ex.Message);
}
finally
{ }
}
else
{
common.salert("您还没有选中有删除的项");
}
}
}
以上就是asp.net gridview多页时的批量删除。承受,继续承受。性命的重量是压在肩头的种种过往和经历。性命的好处,是在你快要趴下的时候咬牙抗住。性命的精彩,是你负重前行,最终到达你梦里以前到过的地方。更多关于asp.net gridview多页时的批量删除请关注haodaima.com其它相关文章!