关于传值分页问题请老鸟出马
.cs 代码 前台访问地址:/webpage.aspx?type=4
问题:如何将type=4的值赋给
string sqlStr = "select * from land_info where info_type=" + type + " order by info_id desc";
和
string sqlStr = "select count(*) from land_info where info_type=" +type + "";
问题补充,固定type=3 的值可以测试通过
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
public partial class info_webpage : System.Web.UI.Page
{
//public int type;
//string stype = Request.QueryString["type"].ToString();//获取文章分类
//int type = Int16.Parse(stype);
protected void Page_Load(object sender, EventArgs e)
{
//string stype = Request.QueryString["type"].ToString();//获取文章分类
//type = Int16.Parse(stype);
if (!Page.IsPostBack)
{ BindGrid(); }
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
BindGrid();
}
public void BindGrid()
{
this.AspNetPager1.RecordCount = Int32.Parse(db.GetAllCount().ToString());
int pageIndex = this.AspNetPager1.CurrentPageIndex - 1;
int pageSize = this.AspNetPager1.PageSize = 20;
Repeater1.DataSource = db.GetCurrentPage(pageIndex, pageSize);
Repeater1.DataBind();
}
//用于文章类信息分页
DBAccess db = new DBAccess();
public class DBAccess
{
int type = 3;
private SqlConnection con;
private string DBName = "landTransaction";
//创建连接对象并打开server=
public void Open()
{
if (con == null)
con = new SqlConnection("此处为数据库链接语句");
if (con.State == ConnectionState.Closed)
con.Open();
}
//创建一个命令对象并返回该对象
public SqlCommand CreateCommand(string sqlStr)
{
Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlStr;
cmd.Connection = con;
return cmd;
}
//生成一个对象并返回该结果集第一行第一列
public object GetScalar(string sqlStr)
{
SqlCommand cmd = CreateCommand(sqlStr);
object obj = cmd.ExecuteScalar();
//CommadnBehavior.CloseConnection是将于DataReader的数据库链接关联起来
//当关闭DataReader对象时候也自动关闭链接
return obj;
}
//执行数据库查询并返回一个数据集 [当前页码,每页记录条数]
public DataSet GetCurrentPage(int pageIndex, int pageSize)
{
//设置导入的起始地址
int firstPage = pageIndex * pageSize;
string sqlStr = "select * from land_info where info_type=" + type + " order by info_id desc";
SqlCommand cmd = CreateCommand(sqlStr);
DataSet dataset = new DataSet();
SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
dataAdapter.Fill(dataset, firstPage, pageSize, "outputsell");
cmd.Dispose();
Close();
dataAdapter.Dispose();