default2.aspx.cs

来自「用asp.net开发的考试系统」· CS 代码 · 共 82 行

CS
82
字号
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 Default2 : System.Web.UI.Page
{
    public char[] my = "b".ToCharArray();
    public string[] a;
    PagedDataSource pds;
  public   ArrayList arr=new ArrayList();
    public static int c=1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bind();
            Label1.Text = "总共"+pds.PageCount.ToString()+"页";
         
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        c++;
        bind();
    }
    public void bind()
    {
        string conn = ConfigurationManager.AppSettings["strconn"];
        SqlConnection cn = new SqlConnection(conn);
        cn.Open();
        SqlDataAdapter da = new SqlDataAdapter("select * from xuanzeti order by item_id ", cn);
        DataSet ds = new DataSet();
        da.Fill(ds, "biao1");
       for(int i=0;i<ds.Tables["biao1"].Rows.Count;i++){
       arr.Add( ds.Tables["biao1"].Rows[i][3].ToString());
        }
        
        foreach (string s in arr) {
           a = s.Split(my);
        }
        foreach (string s1 in a ) { Label3.Text += s1; }
      //  char[] my="<br>".ToCharArray();
  
       // foreach (string s in a) {
          //  Label3.Text += s;
       // }
 pds = new PagedDataSource();
        pds.DataSource = ds.Tables["biao1"].DefaultView;
        pds.AllowPaging = true;
        pds.PageSize = 3;
        pds.CurrentPageIndex = c - 1;
        if (pds.IsFirstPage)
        {
            LinkButton2.Enabled = false;
        }
        else if (pds.IsLastPage)
        {
            LinkButton1.Enabled = false;
        }
        else { LinkButton2.Enabled = true; LinkButton1.Enabled = true; }
        Label2.Text = "当前" + c.ToString() + "页";
     

        DataList1.DataSource = pds;
        DataList1.DataBind();
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        c--;
        bind();

    }
}

⌨️ 快捷键说明

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