| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1317 人关注过本帖
标题:定义一个变量怎么在多个事件里调用这个变量啊
取消只看楼主 加入收藏
浩天
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2007-11-17
结帖率:80%
收藏
 问题点数:0 回复次数:2 
定义一个变量怎么在多个事件里调用这个变量啊
在页面的装载事件中取得一个整型变量  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]]
搜索更多相关主题的帖子: 变量 定义 
2008-11-27 22:20
浩天
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2007-11-17
收藏
得分:0 
ViewState的用法和session 完全一样啊
2008-12-14 14:14
浩天
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2007-11-17
收藏
得分:0 
回复 第6楼 hebingbing 的帖子
什么意思哦  
把哪一个定义、为static
2008-12-15 21:23
快速回复:定义一个变量怎么在多个事件里调用这个变量啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013593 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved