string ConnString = ConfigurationManager.ConnectionStrings["OleDB"].ConnectionString
添加命名空间:using System.Data.SqlClient//增删查改
//string sql = ""
//SqlConnection cn=new SqlConnection("连接字符串")
//sql = "insert into table (字段1,字段2) values ('xx','aa')"//增
//sql = "delete from table where table_id ='" + ID + "'"//删
//sql = "select 字段1,字段2 from table where 条件"//查
//sql = "update table set 字段1='',字段2='' where table_id='" + ID + "' "//改
//SqlDataAdapter da = new SqlDataAdapter(sql, cn)
//DataSet ds = new DataSet()
//da.Fill(ds)// 这样就执行了
很简单的,首先打开数据库,查询。绑定到dataset中.net中有一个内置的分页控件,也可以y用储存过程
如:PagedDataSource pds = new PagedDataSource()内置的空间。
ctn.Close()
pds.DataSource = ds.Tables[0].DefaultView读取内容。ds是上面的dataset
pds.PageSize = 20 每页显示的大小
pds.AllowPaging = true 允许分页。
string p = Request.QueryString["p"]
if (p == null)
p = "1"
lb_pjallnum.Text = "共有" + pds.PageCount.ToString() 中分页数+ "页"
pds.CurrentPageIndex = Convert.ToInt32(p) - 1;当前页的索引
if (pds.PageCount >1)判断
{
if (pds.IsFirstPage)
{这里就是上一页,下一也,首页。。。
HyperLink3.NavigateUrl = "shop_fl.aspx?type=viphuiyuanpj&p=" + (Convert.ToInt32(p) + 1)+"&pnum="+pnum+"&search="+TextBox1.Text
HyperLink4.NavigateUrl = "shop_fl.aspx?type=viphuiyuanpj&p=" + pds.PageCount + "&pnum=" + pnum + "&search=" + TextBox1.Text
}
else if (pds.IsLastPage)
{
HyperLink1.NavigateUrl = "shop_fl.aspx?type=viphuiyuanpj&p=1" + "&pnum=" + pnum + "&search=" + TextBox1.Text
HyperLink2.NavigateUrl = "shop_fl.aspx?type=viphuiyuanpj&p=" + (Convert.ToInt32(p) - 1) + "&pnum=" + pnum + "&search=" + TextBox1.Text
}
else
{
HyperLink2.NavigateUrl = "shop_fl.aspx?type=viphuiyuanpj&p=" + (Convert.ToInt32(p) - 1) + "&pnum=" + pnum + "&search=" + TextBox1.Text
HyperLink3.NavigateUrl = "shop_fl.aspx?type=viphuiyuanpj&p=" + (Convert.ToInt32(p) + 1) + "&pnum=" + pnum + "&search=" + TextBox1.Text
HyperLink1.NavigateUrl = "shop_fl.aspx?type=viphuiyuanpj&p=1 " + "&pnum=" + pnum + "&search=" + TextBox1.Text
HyperLink4.NavigateUrl = "shop_fl.aspx?type=viphuiyuanpj&p=" + pds.PageCount + "&pnum=" + pnum + "&search=" + TextBox1.Text
}
}
else
{
HyperLink1.Enabled = false
HyperLink2.Enabled = false
HyperLink3.Enabled = false
HyperLink4.Enabled = false
}
GridView1.DataSource = pds绑定
GridView1.DataBind()
页面你可以用
<asp:DataList ID="DataList1" runat="server">
<HeaderTemplate>这里和下面的东西随便加一些如:表格 div的东西。
可以是表格的头
</HeaderTemplate>
<ItemTemplate>
内容
</ItemTemplate>
<FooterTemplate>
表尾
</FooterTemplate>
</asp:DataList>
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)