cs文件:
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindData();
}
}public void bindData()
{
ClassDB myDB = new ClassDB();
string mySql = "select * from Message order by id desc";
DataSet ds = myDB.getDataSet(mySql);
GridView1.DataSource = ds.Tables[0].DefaultView;
AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows.Count.ToString());
Label2.Text = ds.Tables[0].Rows.Count.ToString();
GridView1.DataBind();
}
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex - 1;
this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
bindData();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindData();
}
}public void bindData()
{
ClassDB myDB = new ClassDB();
string mySql = "select * from Message order by id desc";
DataSet ds = myDB.getDataSet(mySql);
GridView1.DataSource = ds.Tables[0].DefaultView;
AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows.Count.ToString());
Label2.Text = ds.Tables[0].Rows.Count.ToString();
GridView1.DataBind();
}
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex - 1;
this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
bindData();
}
ClassDB类
Code
using System;
using System.Data;
using System.Configuration;
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.SqlClient;
using System.Data.SqlTypes;
/**//// <summary>
/// ClassDB 的摘要说明
/// </summary>
public class ClassDB
{
private SqlConnection conn;
public ClassDB()
{
conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
conn.Open();
}
public ClassDB(string ConnStr)
{
conn = new SqlConnection(ConnStr);
conn.Open();
}
public void Close() //关闭数据库
{
conn.Close();
conn = null;
}
public SqlDataReader getSqlDataReader(string SQLQuery)
{
SqlCommand cmd = new SqlCommand(SQLQuery, conn);
return cmd.ExecuteReader();
}
public int Insert(string SQLQuery)//插入
{
SqlCommand cmd = new SqlCommand(SQLQuery, conn);
return cmd.ExecuteNonQuery();
}
public int Update(string SQLQuery)//更新
{
SqlCommand cmd = new SqlCommand(SQLQuery, conn);
return cmd.ExecuteNonQuery();
}
public int Delete(string SQLQuery)//删除
{
SqlCommand cmd = new SqlCommand(SQLQuery, conn);
return cmd.ExecuteNonQuery();
}
public DataSet getDataSet(string SQLQuery)
{
SqlDataAdapter da = new SqlDataAdapter(SQLQuery, conn);
DataSet ds = new DataSet();
da.Fill(ds);
da.Dispose();
da = null;
return ds;
}
}
using System;
using System.Data;
using System.Configuration;
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.SqlClient;
using System.Data.SqlTypes;
/**//// <summary>
/// ClassDB 的摘要说明
/// </summary>
public class ClassDB
{
private SqlConnection conn;
public ClassDB()
{
conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
conn.Open();
}
public ClassDB(string ConnStr)
{
conn = new SqlConnection(ConnStr);
conn.Open();
}
public void Close() //关闭数据库
{
conn.Close();
conn = null;
}
public SqlDataReader getSqlDataReader(string SQLQuery)
{
SqlCommand cmd = new SqlCommand(SQLQuery, conn);
return cmd.ExecuteReader();
}
public int Insert(string SQLQuery)//插入
{
SqlCommand cmd = new SqlCommand(SQLQuery, conn);
return cmd.ExecuteNonQuery();
}
public int Update(string SQLQuery)//更新
{
SqlCommand cmd = new SqlCommand(SQLQuery, conn);
return cmd.ExecuteNonQuery();
}
public int Delete(string SQLQuery)//删除
{
SqlCommand cmd = new SqlCommand(SQLQuery, conn);
return cmd.ExecuteNonQuery();
}
public DataSet getDataSet(string SQLQuery)
{
SqlDataAdapter da = new SqlDataAdapter(SQLQuery, conn);
DataSet ds = new DataSet();
da.Fill(ds);
da.Dispose();
da = null;
return ds;
}
}
页面文件:
Code
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AllowPaging="True" Height="173px" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" Width="355px" style="border-left-color: silver; border-bottom-color: silver; font: messagebox; color: black; border-top-color: silver; border-right-color: silver; border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none;" PageSize="20">
<Columns>
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
<font color="000000">第</font><asp:Label ID="Label6" runat="server" Style=" color: #000000"
Text='<%# DataBinder.Eval(Container.DataItem, "id")%>'></asp:Label><font color="000000">位签名者</font>
</ItemTemplate>
<HeaderStyle BackColor="#E0E0E0" Width="30px" />
<ItemStyle Height="30px" Wrap="False" />
</asp:TemplateField>
<asp:BoundField DataField="User_Name" HeaderText="爱国者" >
<HeaderStyle BackColor="#E0E0E0" Height="30px" Wrap="False" />
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField HeaderText="地区" DataField="User_City" >
<HeaderStyle BackColor="#E0E0E0" Height="30px" Wrap="False" />
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="User_Datetime" HeaderText="签名历史时刻" >
<HeaderStyle BackColor="#E0E0E0" Height="30px" Wrap="False" />
<ItemStyle Wrap="False" />
</asp:BoundField>
</Columns>
<PagerSettings PageButtonCount="16" Visible="False" />
</asp:GridView>
<br />
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" CurrentPageButtonTextFormatString="[{0}]"
NextPageText="下一页" PrevPageText="上一页" OnPageChanged="AspNetPager1_PageChanged" style="font: messagebox" FirstPageText="" LastPageText="" ShowPageIndexBox="Never" OnPageChanging="AspNetPager1_PageChanging">
</webdiyer:AspNetPager>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AllowPaging="True" Height="173px" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" Width="355px" style="border-left-color: silver; border-bottom-color: silver; font: messagebox; color: black; border-top-color: silver; border-right-color: silver; border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none;" PageSize="20">
<Columns>
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
<font color="000000">第</font><asp:Label ID="Label6" runat="server" Style=" color: #000000"
Text='<%# DataBinder.Eval(Container.DataItem, "id")%>'></asp:Label><font color="000000">位签名者</font>
</ItemTemplate>
<HeaderStyle BackColor="#E0E0E0" Width="30px" />
<ItemStyle Height="30px" Wrap="False" />
</asp:TemplateField>
<asp:BoundField DataField="User_Name" HeaderText="爱国者" >
<HeaderStyle BackColor="#E0E0E0" Height="30px" Wrap="False" />
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField HeaderText="地区" DataField="User_City" >
<HeaderStyle BackColor="#E0E0E0" Height="30px" Wrap="False" />
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="User_Datetime" HeaderText="签名历史时刻" >
<HeaderStyle BackColor="#E0E0E0" Height="30px" Wrap="False" />
<ItemStyle Wrap="False" />
</asp:BoundField>
</Columns>
<PagerSettings PageButtonCount="16" Visible="False" />
</asp:GridView>
<br />
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" CurrentPageButtonTextFormatString="[{0}]"
NextPageText="下一页" PrevPageText="上一页" OnPageChanged="AspNetPager1_PageChanged" style="font: messagebox" FirstPageText="" LastPageText="" ShowPageIndexBox="Never" OnPageChanging="AspNetPager1_PageChanging">
</webdiyer:AspNetPager>