using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind(0,name);
pageindex = 0;
name = "";
}
} private void Bind(int index,string ename)
{
using (SqlConnection con = new SqlConnection("server=.;database=News;uid=sa;pwd=123"))
{
con.Open();
if (ename == null || ename == "" )
{
string sql = string.Format("select top 10 * from newsinfo where newsID not in (select top {0} newsID from newsinfo)", index);
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind(); if (pageindex == (pagecount - 1))
{
LinkButton1.Enabled = false;
LinkButton2.Enabled = true;
}
else if (pageindex == 0)
{
LinkButton1.Enabled = true;
LinkButton2.Enabled = false;
}
else if (pageindex != 0 && pageindex != (pagecount - 1))
{
LinkButton1.Enabled = true;
LinkButton2.Enabled = true;
}
string sqlstr = "select count(*) from newsinfo";
SqlCommand cmd = new SqlCommand(sqlstr, con);
int count = int.Parse(cmd.ExecuteScalar().ToString());
pagecount = count % 10 == 0 ? count / 10 : (count / 10 + 1);
}
else
{
string sql = string.Format("select top 10 * from newsinfo where newsID not in (select top {0} newsID from newsinfo ) and newstype='{1}'", index, name);
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind(); if (pageindex == (pagecount - 1))
{
LinkButton1.Enabled = false;
LinkButton2.Enabled = true;
}
else if (pageindex == 0)
{
LinkButton1.Enabled = true;
LinkButton2.Enabled = false;
}
else if (pageindex != 0 && pageindex != (pagecount - 1))
{
LinkButton1.Enabled = true;
LinkButton2.Enabled = true;
}
string sqlstr = string.Format("select count(*) from newsinfo where newstype={0}",name);
SqlCommand cmd = new SqlCommand(sqlstr, con);
int count = int.Parse(cmd.ExecuteScalar().ToString());
pagecount = count % 10 == 0 ? count / 10 : (count / 10 + 1);
} }
}
static int pageindex;
static int pagecount;
static string name; protected void LinkButton1_Click(object sender, EventArgs e)
{
pageindex = pageindex + 1;
Bind(pageindex * 10, name);
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
pageindex = pageindex - 1;
Bind(pageindex * 10, name);
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
pageindex = 0;
Bind(pageindex * 10, name);
}
protected void LinkButton4_Click1(object sender, EventArgs e)
{
pageindex = pagecount - 1;
Bind(pageindex * 10, name);
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) //选择不同的新闻类型
{
name = DropDownList1.SelectedValue.ToString();
Label1.Text = name;
Bind(0, name);
}
}
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind(0,name);
pageindex = 0;
name = "";
}
} private void Bind(int index,string ename)
{
using (SqlConnection con = new SqlConnection("server=.;database=News;uid=sa;pwd=123"))
{
con.Open();
if (ename == null || ename == "" )
{
string sql = string.Format("select top 10 * from newsinfo where newsID not in (select top {0} newsID from newsinfo)", index);
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind(); if (pageindex == (pagecount - 1))
{
LinkButton1.Enabled = false;
LinkButton2.Enabled = true;
}
else if (pageindex == 0)
{
LinkButton1.Enabled = true;
LinkButton2.Enabled = false;
}
else if (pageindex != 0 && pageindex != (pagecount - 1))
{
LinkButton1.Enabled = true;
LinkButton2.Enabled = true;
}
string sqlstr = "select count(*) from newsinfo";
SqlCommand cmd = new SqlCommand(sqlstr, con);
int count = int.Parse(cmd.ExecuteScalar().ToString());
pagecount = count % 10 == 0 ? count / 10 : (count / 10 + 1);
}
else
{
string sql = string.Format("select top 10 * from newsinfo where newsID not in (select top {0} newsID from newsinfo ) and newstype='{1}'", index, name);
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind(); if (pageindex == (pagecount - 1))
{
LinkButton1.Enabled = false;
LinkButton2.Enabled = true;
}
else if (pageindex == 0)
{
LinkButton1.Enabled = true;
LinkButton2.Enabled = false;
}
else if (pageindex != 0 && pageindex != (pagecount - 1))
{
LinkButton1.Enabled = true;
LinkButton2.Enabled = true;
}
string sqlstr = string.Format("select count(*) from newsinfo where newstype={0}",name);
SqlCommand cmd = new SqlCommand(sqlstr, con);
int count = int.Parse(cmd.ExecuteScalar().ToString());
pagecount = count % 10 == 0 ? count / 10 : (count / 10 + 1);
} }
}
static int pageindex;
static int pagecount;
static string name; protected void LinkButton1_Click(object sender, EventArgs e)
{
pageindex = pageindex + 1;
Bind(pageindex * 10, name);
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
pageindex = pageindex - 1;
Bind(pageindex * 10, name);
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
pageindex = 0;
Bind(pageindex * 10, name);
}
protected void LinkButton4_Click1(object sender, EventArgs e)
{
pageindex = pagecount - 1;
Bind(pageindex * 10, name);
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) //选择不同的新闻类型
{
name = DropDownList1.SelectedValue.ToString();
Label1.Text = name;
Bind(0, name);
}
}
解决方案 »
- 求DEVEXPRESS FOR VS2008 OR 2010
- 鼠标划过GRIDVIEW记录 弹出隐藏层显示图片
- javascript 的$.post()传值问题?
- asp.net中对象有哪些???
- treeview 展开某一节点,关闭其兄弟节点(并记住其状态,如CHECKBOX选中),在MS TREEVIEW 里修改HTC源码实现,怎么修改啊
- 如何算出一个时间段的时间.
- 这是个问题,一定要给100分
- 求购一套邮件系统包括服务器和客户端(带源码)价格面议 ycdf()解决问题接分
- 问一个简单的函数返回值问题,刚学,别见笑,多谢帮忙!!!
- asp.net怎样使用事务,请高手。。。
- 一个很棘手的问题!想了一天了没解决!帮帮忙吧!在线等,很急!
- System.ArgumentNullException: 值不能为空。
选择不同的类型,查询出不同类型的新闻,然后给不同类型的新闻分页功能
当然,首页加载的时候是查询所有的新闻的
当改变DropDownList1的时候会变化(我的设计),但是
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) //选择不同的新闻类型
{
name = DropDownList1.SelectedValue.ToString();
Label1.Text = name;
Bind(0, name);
}
这段代码的name取不到值 那是为什么?
请指教
代码有些冗余
勉强看看
是做分页实验用的