定义一个变量怎么在多个事件里调用这个变量啊
在页面的装载事件中取得一个整型变量 tid,在LinkButton1每次的Click事件里都对tid加1,LinkButton2的Click 事件里都对tid减1,该怎么做啊我每次单击LinkButton1时tid都为0啊。
而且ablename会为null.
大家看哈着代码该怎么写啊
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 content : System.Web.UI.Page
{
public int tid;
public string tablename;
public void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
tid = Request.QueryString["titleid"];
tablename = Session["tablename"].ToString()
String titleid ;
titleid = tid;
string sql = "select content from " + tablename + " where titleid=" + titleid.ToString();
SqlConnection mycn = new SqlConnection();
mycn.ConnectionString = "server=.;database=book;trusted_connection=yes";
DataSet myds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, mycn);
da.Fill(myds);
DataList1.DataSource = myds;
DataList1.DataBind();
if (titleid <= 1)
{
LinkButton1.text="当前以是第一页";
LinkButton1.Enabled = false;
}
}
}
public void LinkButton1_Click(object sender, EventArgs e)
{
tid=tid+1;
String titleid ;
titleid = tid;
string sql = "select content from " + tablename + " where titleid=" + titleid.ToString();
SqlConnection mycn = new SqlConnection();
mycn.ConnectionString = "server=.;database=book;trusted_connection=yes";
DataSet myds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, mycn);
da.Fill(myds);
DataList1.DataSource = myds;
DataList1.DataBind();
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
tid=tid-1;
String titleid ;
titleid = tid;
string sql = "select content from " + tablename + " where titleid=" + titleid.ToString();
SqlConnection mycn = new SqlConnection();
mycn.ConnectionString = "server=.;database=book;trusted_connection=yes";
DataSet myds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, mycn);
da.Fill(myds);
DataList1.DataSource = myds;
DataList1.DataBind();
}
}
[[it] 本帖最后由 浩天 于 2008-11-27 22:22 编辑 [/it]]