BackColor="White" BorderColor="#CC9966" BorderStyle="Solid"
BorderWidth="1px" CellPadding="4" DataKeyNames="流水号"
Height="87px" Width="637px" AllowPaging="true" HorizontalAlign="Center"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowDeleting="GridView1_RowDeleting" PageSize="6"
OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
<!--进行分页,每页6条-->
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="流水号"
DataNavigateUrlFormatString="~/shownew.aspx?id={0}"
DataTextField="新闻标题" DataTextFormatString="·{0}"
HeaderText="新闻标题" Target="_blank">
<ItemStyle HorizontalAlign="Left" />
</asp:HyperLinkField>
<!--获取“流水号这个键值”,要打开的页面和传递的id参数,标题为“新闻标题” -->
<asp:BoundField DataField="新闻类别" DataFormatString="[{0}]" HeaderText="新闻类别"/>
<asp:BoundField DataField="阅读次数" DataFormatString="[{0}]" HeaderText="阅读次数"/>
<asp:BoundField DataField="添加时间" HeaderText="添加时间"/>
<asp:CommandField ShowCancelButton="false" ShowDeleteButton="true" />
<!--添加删除项-->
</Columns>
<PagerStyle BackColor="#FFFFCC" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<PagerSettings FirstPageText="" LastPageText="" Mode="NextPrevious" NextPageText="下一页"
PageButtonCount="6" PreviousPageText="上一页" />
<!--加入上一页和下一页-->
</asp:GridView>
public partial class delnews : System.Web.UI.Page
{//创建BaseClass对象
BaseClass ba = new BaseClass();
protected void Page_Load(object sender, EventArgs e)
{
bindgrig();//开始调用
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{//当点击上一页和下一页时,就回触发该事件
GridView1.PageIndex = e.NewPageIndex;
bindgrig();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{//执行删除语句
String strsql = "delete from 新闻信息表 where 流水号=" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "";
ba.execsql(strsql);
bindgrig();
}
void bindgrig()
{//在GridView1控件中显示数据
string strsql = "select * from 新闻信息表 order by 流水号";
DataTable dt = ba.readtable(strsql);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}