asp.Netリフレッシュページインスタンスコードなし

7815 ワード

データクラスコード:
 
  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Reflection;

namespace DAL
{
    public  class UserManageClass
    {
        ///


        ///
        ///

        ///
        public int GetPageCount()
        {
            int counts;
            string SqlStr = "select count(0) from [User]";
            counts = new SQLHelper().Content(SqlStr, CommandType.Text);
            return counts;
        }
        ///
        ///
        ///

        ///
        ///
        ///
        public DataTable GetPageDate(string SatrPage, string EndPage)
        {
            DataTable dt;
            string SqlStr = @"select * from
            (select *, ROW_NUMBER() over(order by id)as no_ from [User])aa
            where aa.no_ between '"+SatrPage+"' and '"+EndPage+"'";
            dt = new SQLHelper().ExecuteQuery(SqlStr, CommandType.Text);
            return dt;
        }

        ///


        /// DataTable
        ///

        ///
        /// DataTable
        ///
        public  List DataTableToEntityList(DataTable dt)
        {
            List entiyList = new List();

            Type entityType = typeof(T);
            PropertyInfo[] entityProperties = entityType.GetProperties();

            foreach (DataRow row in dt.Rows)
            {
                T entity = Activator.CreateInstance();

                foreach (PropertyInfo propInfo in entityProperties)
                {
                    if (dt.Columns.Contains(propInfo.Name))
                    {
                        if (!row.IsNull(propInfo.Name))
                        {
                            propInfo.SetValue(entity, row[propInfo.Name], null);
                        }
                    }
                }

                entiyList.Add(entity);
            }

            return entiyList;
        }


    }
}


PageService.ashx.cs一般ハンドラコード:
 
  
using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.SqlClient;
using DAL;
using System.Web.Extensions;
using System.Web.Script.Serialization;
using Model;
using System.Web.UI.MobileControls;
using System.Collections.Generic;

namespace LandingSystem
{
    ///


    /// $codebehindclassname$
    ///

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class PageService : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request["action"];
            if (action == "GetPageCount")
            {
                int counts = new UserManageClass().GetPageCount();
                int page = counts / 3;
                if (counts % 3 != 0)
                {
                    page++;
                }
                context.Response.Write(page);
            }
            else if (action == "GetPageData")
            {
                int pageNo = Convert.ToInt32(context.Request["PageNo"]);
                string SatrPage = ((pageNo - 1) * 3 + 1).ToString();
                string EndPage = (pageNo * 3).ToString();
                DataTable dt= new UserManageClass().GetPageDate(SatrPage, EndPage);
                IList data = ModelConvertHelper.ConvertToModel(dt);
               // IList data = new UserManageClass().DataTableToEntityList(dt);
                var p1 = data.Select(c => new { c.Name,c.Phone});
                #region
                // var p1 = data.Select( c => new { c.Name,c.Phone});
                //var p1=data.Select(dr=>new {dr["Name"].ToString(),dr["Phone"].ToString()});


                //var T_model = new List();               
                //var p3 = T_model.Select(c => new { c.Name, c.Phone });

                //var p2=data.Select(c=>new {})
                #endregion
                JavaScriptSerializer jss = new JavaScriptSerializer();
                context.Response.Write(jss.Serialize(p1));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}


aspxページコード:
 
  

   

   
    <br>$(function(){ <br>//----------------------------------------------------------- <br>function getPageData(pageNo){ // <br>$.post("PageService.ashx",{"action":"GetPageData","PageNo":pageNo},function(data,status){ <br>if(status=="success"){ <br>$("#Comment").empty(); <br>var comments=$.parseJSON(data); // json 。 <br>for(var i=0;i<comments.length;i++){ <br>var row=comments[i]; <br>var li= $("<li>"+row.Name+" : "+row.Phone+"</li>"); <br>$("#Comment").append(li); // li append Comment/ul 。 <br>} <br>} <br>}); <br>} <br>//------------------------------------------------------------------- <br>getPageData(1); // , <br>//----------------------------------------------------------------/ <br>// <br>$.post("PageService.ashx",{"action":"GetPageCount"},function(data,status){ <br>if(status=="success"){ <br>var tr1=$("<tr></tr>"); <br>var pageNo=parseInt(data); <br>for(var i=1;i<=pageNo;i++){ <br>var td=$("<td><a href=''>"+i+"</a></td>"); <br>tr1.append(td); <br>} <br>$("#pageNo").append(tr1); <br>$("#pageNo a").click(function(e){ // , click 。 <br>e.preventDefault(); // a <br>getPageData($(this).html()); // 。 <br>}); <br>} <br>}); <br>//---------------------------------------------------------------------------- <br>}); <br>



   
       
   

       

           

   

    :