⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 default.aspx.cs

📁 microsoft公司在进行ASP.NET 2.0培训课时课堂操作演示代码。
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.LabelNow.Text = "1";
            GetNewsInfoData();
            if (Session["username"] != null && Session["pwd"]!=null)
            {
                string username = Session["username"].ToString();
                string pwd = Session["pwd"].ToString();

                Response.Write("你的用户名是:" + username + "<br>密码是:" + pwd);
            }
        }
    }
    private void GetNewsInfoData()
    {
        string constr = System.Configuration.ConfigurationManager.ConnectionStrings["NewsDBConnectionString"].ConnectionString;
        SqlConnection Con = new SqlConnection(constr);
         string Sql = "select * from NewsInfo";
         SqlDataAdapter Sda = new SqlDataAdapter(Sql,Con);
         DataSet Ds = new DataSet();
         Sda.Fill(Ds,"NewsInfo");
         PagedDataSource Ps = new PagedDataSource();
         Ps.DataSource = Ds.Tables[0].DefaultView;
         Ps.AllowPaging = true;
         Ps.PageSize = 2;
         this.LabelTotal.Text = Ps.PageCount.ToString();
         Ps.CurrentPageIndex=(Int32.Parse(this.LabelNow.Text))-1;
         this.BtnNext.Enabled = true;
         this.BtnPre.Enabled = true;
        if(Ps.CurrentPageIndex==0)
        {
            this.BtnPre.Enabled = false;
        }
        if(Ps.CurrentPageIndex==(Ps.PageCount-1))
        {
            this.BtnNext.Enabled = false;
        }
        this.DataList1.DataSource = Ps;
        this.DataList1.DataBind();
    }

    public string GetStr(string str)
    { 
       if(str.Length>10)
       {
           return str.Substring(0,10)+"....";
       }
        else
       {
           return str;
       }
    }
    protected void BtnFirst_Click(object sender, EventArgs e)
    {
        this.LabelNow.Text = "1";
        GetNewsInfoData();
    
    }
    protected void BtnPre_Click(object sender, EventArgs e)
    {
        this.LabelNow.Text = (Int32.Parse(this.LabelNow.Text) - 1).ToString();
        GetNewsInfoData();
    }
    protected void BtnNext_Click(object sender, EventArgs e)
    {
        this.LabelNow.Text = (Int32.Parse(this.LabelNow.Text) + 1).ToString();
        GetNewsInfoData();
    }
    protected void btnLast_Click(object sender, EventArgs e)
    {
        this.LabelNow.Text = this.LabelTotal.Text;
        this.GetNewsInfoData();
    }
    protected void Login1_LoggedIn(object sender, EventArgs e)
    {
        string username = this.Login1.UserName;
        if (Roles.IsUserInRole(username, "administrator"))
        {
            Response.Redirect("~/admins/NewsManage.aspx");
        }
        else
        { 
          if(Roles.IsUserInRole(username,"Blogers"))
          {
              Response.Redirect("~/Blogers/LogsManage.aspx");
          }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -