datalist的分页

来源:互联网 发布:mysql修改数据库名称 编辑:程序博客网 时间:2024/05/16 17:29

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 aLeave : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string name = Request.Form["username"].ToString();
        string from = Request.Form["come"].ToString();
        string content = Request.Form["content"].ToString();
        string homePge = Request.Form["homepage"].ToString();
        string qq = Request.Form["qq"].ToString();
        RegexStringValidator reg=new RegexStringValidator("//d{6,15}");
        try
        {
            reg.Validate((object)qq);
        }
        catch
        {
            Response.Redirect("error.htm");
        }
        int aqq = Convert.ToInt32(qq);
        dataBase(name,from, content, homePge, aqq);

    }
    void dataBase(string name,string from,string content,string homePge,int qq)
    {
        SqlConnection scon = new SqlConnection(ConfigurationManager.AppSettings["ConnString"].ToString());
        SqlCommand scom = new SqlCommand();
        scom.Connection = scon;
        scom.CommandText = "insert into MV100_NoteBook(notePeople,ipFrom,noteContent,wPro) values(@notePeople,@ipFrom,@noteContent,@wPro) ";
        scom.Parameters.Add("@notePeople",SqlDbType.VarChar);
        scom.Parameters["@notePeople"].Value = name;

        scom.Parameters.Add("@ipFrom", SqlDbType.VarChar);
        scom.Parameters["@ipFrom"].Value = from;

        scom.Parameters.Add("@noteContent", SqlDbType.VarChar);
        scom.Parameters["@noteContent"].Value =content;

        scom.Parameters.Add("@wPro", SqlDbType.Int);
        scom.Parameters["@wPro"].Value =qq;
        try
        {
            scon.Open();
            scom.ExecuteNonQuery();
            int re = recordCount();
            Response.Redirect("Leave.aspx");
            //if (re > 8)
            //{
            //    if (re % 8 != 0)
            //    {
            //        Response.Redirect("Leave.aspx?nIn=" + Convert.ToInt32(re / 8 + 1));
            //    }
            //    else
            //    {
            //        Response.Redirect("Leave.aspx?nIn=" + Convert.ToInt32(re / 8));
            //    }
            //}
            //else
            //{
            //    Response.Redirect("Leave.aspx");
            //}

          
        }
        catch (Exception ee)
        {
            Response.Write("<script language=javascript>alert('" + ee.Message + "')</script>");
        }
        finally
        {
            scon.Close();
        }
    }
    int recordCount()
    {
        SqlConnection scon = new SqlConnection(ConfigurationManager.AppSettings["ConnString"].ToString());
        SqlCommand scom = new SqlCommand("select count(*) from MV100_NoteBook", scon);
        scon.Open();
        int recordSetCount = Convert.ToInt32(scom.ExecuteScalar());
        scon.Close();
        return recordSetCount;
    }
}

原创粉丝点击