/// <summary>
/// 塗聚文
/// 20140225
/// </summary>
public partial class DatatablePage : System.Web.UI.Page
{ /// <summary>
/// 测试 分页数据
/// </summary>
DataTable pageDt;
/// <summary>
///
/// </summary>
public void geovinduDt()
{
pageDt = new DataTable();
pageDt.Columns.Add("id", typeof(int));
pageDt.Columns.Add("ddno", typeof(string));
pageDt.Columns.Add("dd", typeof(string));
//dtyhdd.Rows.Add("1", "n1");
//dtyhdd.Rows.Add("2", "n2");
for (int i = 1; i <= 31; i++)
{
//保存到内存表中
DataRow tr = this.pageDt.NewRow();
tr["id"] = i;
tr["ddno"] = i.ToString();
tr["dd"] = i.ToString() + "内容";
pageDt.Rows.Add(tr);
} } /// <summary>
/// 隐患地点共分多少页
/// </summary>
int verypage = 0;
/// <summary>
/// 隐患当前页
/// </summary>
int currentPage = 0;
/// <summary>
/// 每页显示多少数据
/// </summary>
int PageSize = 1; /// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack)
{ if (!string.IsNullOrEmpty(Request.QueryString["page"]))
{
currentPage = int.Parse(Request.QueryString["page"]);
}
currentPage++; this.TextBox1.Text = currentPage.ToString();
//【初始化数据】
geovinduDt();
//【执行分页显示】 //每次显示10条数据 需要多少次
verypage = pageDt.Rows.Count / 1;
//是否有余数
int numys = pageDt.Rows.Count % 1;
if (numys > 0)
{
currentPage++;
}
//comyhdd.Items.Clear();
if (currentPage >= pageDt.Rows.Count)
{
Button1.Enabled = false;
return;
} DataRow[] mMatches = pageDt.Select("(id=" + currentPage + ")");
//DataRow matches = new DataRow(); string strName = mMatches[0]["dd"].ToString(); DataSet pDS = new System.Data.DataSet();
System.Data.DataTable mDT = pageDt.Clone();
mDT.Clear();
//mDT.TableName = mTableName;
//mDT = mDT.Clone();
for (int i = 0; i < mMatches.Length; i++)
{
mDT.Rows.Add(mMatches[i].ItemArray);
}
pDS.Tables.Add(mDT);
//1
Repeater1.DataSource = GetPagedTable(pageDt, currentPage, PageSize);
Repeater1.DataBind();
//2
//Repeater1.DataSource = pDS;
//Repeater1.DataBind(); this.TextBox1.Text = strName;
//Repeater1.DataSource = GetPagedTable(pageDt, yhdddqi, PageSize);
//Repeater1.DataBind();
this.Label1.Text = currentPage.ToString() + "/" + verypage; } }
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
verypage = 1; //下一页
if (!string.IsNullOrEmpty(Request.QueryString["page"]))
{
currentPage = int.Parse(Request.QueryString["page"]);
}
currentPage++;
geovinduDt();
if (currentPage >= pageDt.Rows.Count)
{
Button1.Enabled = false;
return;
} DataRow[] mMatches = pageDt.Select("(id=" + currentPage + ")");
//DataRow matches = new DataRow();
string strName = mMatches[0]["dd"].ToString();
this.TextBox1.Text = strName;
string answer = string.Empty;
if (CheckBoxA.Checked == true)
{
answer = "A";
}
if (CheckBoxB.Checked == true)
{
if (!string.IsNullOrEmpty(answer))
{
answer = answer + "," + "B";
}
else
{
answer = "B";
}
}
if (CheckBoxC.Checked == true)
{
if (!string.IsNullOrEmpty(answer))
{
answer = answer + "," + "C";
}
else
{
answer = "C";
}
}
if (CheckBoxD.Checked == true)
{
if (!string.IsNullOrEmpty(answer))
{
answer = answer + "," + "D";
}
else
{
answer = "D";
}
}
Jscript.Alert(answer);
this.Label1.Text = currentPage.ToString() + "/" + verypage;
Response.Redirect("DatatablePage.aspx?page=" + (currentPage) + "&name=" + strName); } /// <summary>
/// DataTable分页
/// </summary>
/// <param name="dt">DataTable</param>
/// <param name="PageIndex">页索引,注意:从1开始</param>
/// <param name="PageSize">每页大小</param>
/// <returns></returns>
public static DataTable GetPagedTable(DataTable dt, int currentPageIndex, int pageSize)
{ //1
//判断当前索引
if (currentPageIndex == 0)
return dt;
//从数据集合拷贝数据
DataTable newdt = dt.Copy();
//数据清空
newdt.Clear();
//开始数据索引 = 当前页-1 x 每页大小
int rowbegin = (currentPageIndex - 1) * pageSize;
//结束数据索引 = 当前页 x 每页大小
int rowend = currentPageIndex * pageSize;
//开始数据索引 大于等于 当前数据集合大小
if (rowbegin >= dt.Rows.Count)
return newdt;
//结束数据索引 大于 当前数据集合大小
if (rowend > dt.Rows.Count)
rowend = dt.Rows.Count;
//遍历数据
for (int i = rowbegin; i <= rowend - 1; i++)
{
DataRow newdr = newdt.NewRow();
DataRow dr = dt.Rows[i];
foreach (DataColumn column in dt.Columns)
{
newdr[column.ColumnName] = dr[column.ColumnName];
}
newdt.Rows.Add(newdr);
} return newdt; //2
//if (currentPageIndex == 0)
//{
//return dt;
//} //DataTable newdt = dt.Clone();// dt.Copy(); //int rowbegin = (currentPageIndex - 1) * pageSize;//当前页的第一条数据在dt中的位置
//int rowend = currentPageIndex * pageSize;//当前页的最后一条数据在dt中的位置 //if (rowbegin >= dt.Rows.Count)
//{
// return newdt;
//} //if (rowend > dt.Rows.Count)
//{
// rowend = dt.Rows.Count;
//} //DataView dv = dt.DefaultView;
//for (int i = rowbegin; i <= rowend - 1; i++)
//{
// newdt.ImportRow(dv[i].Row);
//} //return newdt; }
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DatatablePage.aspx.cs" Inherits="ShoppingDeals.Admin.VipHKExamSystem.DatatablePage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Datatable paging,Repeater with Paging </title>
<meta name="author" content="塗聚文" />
</head>
<body>
<form id="form1" runat="server">
<div> <table style="width:100%;">
<tbody>
<tr>
<td>id</td>
<td>name:</td>
</tr>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate> <tr>
<td><%# Eval("ddno").ToString()%></td>
<td><%# Eval("dd").ToString()%></td>
</tr> </ItemTemplate>
</asp:Repeater> </tbody>
</table> <div><b>選擇答案:</b><asp:CheckBox ID="CheckBoxA" runat="server" Text="A" /><asp:CheckBox ID="CheckBoxB" runat="server" Text="B"/><asp:CheckBox ID="CheckBoxC" runat="server" Text="C"/><asp:CheckBox ID="CheckBoxD" runat="server" Text="D"/></div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="下一頁" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div>
</form>
</body>
</html>
  public partial class ExamCNTestDisplay : System.Web.UI.Page
{
VIPExamQuestionsBLL vIPExamQuestionsBLL = new VIPExamQuestionsBLL();
VipExamProjectBLL vipExamProjectBLL = new VipExamProjectBLL();
VipExamProjectInfo vipExamProjectInfo = new VipExamProjectInfo();
string examProjectId = string.Empty;
int fcount = 0;
int _currentPage = 0;
int k = 0;
/// <summary>
///
/// </summary>
public int currentPage
{
set { _currentPage = value; }
get { return _currentPage; }
} public int getPage = 1; DataTable Tissues =new DataTable();
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{ //DataTable Tissues = (DataTable)Session["Tissues"]; if (Tissues.Rows.Count==0)
{
Tissues.Columns.Add("ID", typeof(int));
Tissues.Columns.Add("Answer", typeof(string));
} if (!IsPostBack)
{
examProjectId = Request.QueryString["DisID"];
if (k == 0)
{
ViewState["ExamProjectId"] = Request.QueryString["DisID"];
k++;
}
else
{ examProjectId = ViewState["ExamProjectId"].ToString();
k++;
}
////Session["BackLogin"] = "ExamProjectList.aspx";
//if (object.Equals(Session["ExamAdminLogin"], null))
//{ // Jscript.AlertAndRedirect("沒有登錄無權限!", "VIPExamLogin.aspx");
//}
if (!string.IsNullOrEmpty(examProjectId))
{
vipExamProjectInfo = vipExamProjectBLL.SelectVipExamProject(int.Parse(examProjectId));
if (!object.Equals(vipExamProjectInfo, null))
{
Page.Title = vipExamProjectInfo.ExamProjectTitle; } PagedDataSource pds = new PagedDataSource();
if (!object.Equals(vIPExamQuestionsBLL.SelectVipQuestionsExamProjectDisplay(int.Parse(examProjectId)), null))
{
pds.DataSource = getdatatable(vIPExamQuestionsBLL.SelectVipQuestionsExamProjectDisplay(int.Parse(examProjectId))).DefaultView; //pds.AllowCustomPaging = true;
pds.AllowPaging = true;
//pds.AllowServerPaging = true;
pds.PageSize = 1;
fcount = pds.Count;
currentPage = Convert.ToInt32(Request["page"]);
//设当前页
pds.CurrentPageIndex = currentPage; getPage = currentPage;
FormView1.DataSource = pds;
FormView1.DataBind();
//设几个超链接 if (!pds.IsFirstPage)
{
lnkUp.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (currentPage - 1);
//LinkButton1.ResolveClientUrl(Request.CurrentExecutionFilePath + "?page=" + (currentPage - 1));
} if (!pds.IsLastPage)
{
//LinkButton1.ResolveClientUrl (Request.CurrentExecutionFilePath + "?page=" + (currentPage - 1)); lnkDown.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (currentPage + 1) + "&DisID=" + examProjectId;
((Label)FormView1.Controls[0].FindControl("Label3")).Text = (currentPage + 1).ToString();
//bool ca = CheckBoxA.Checked;CheckBoxA
//bool cb = CheckBoxB.Checked;
//bool cc = CheckBoxC.Checked;
//bool cd = CheckBoxD.Checked;
//FormView1.DefaultMode = FormViewMode.Insert;
CheckBox CheckBoxA = (CheckBox)FormView1.Controls[0].FindControl("CheckBoxA");//(CheckBox)FormView1.Row.FindControl("CheckBoxA");//
CheckBox CheckBoxB = (CheckBox)FormView1.Controls[0].FindControl("CheckBoxB");
CheckBox CheckBoxC = (CheckBox)FormView1.Controls[0].FindControl("CheckBoxC");
CheckBox CheckBoxD = (CheckBox)FormView1.Controls[0].FindControl("CheckBoxD");
HtmlInputCheckBox CheckBox1 = (HtmlInputCheckBox)FormView1.Controls[0].FindControl("CheckBox1");
string answer = string.Empty;
if (FormView1.CurrentMode == FormViewMode.ReadOnly)
{
// Jscript.Alert(CheckBoxB.Checked.ToString()); if (CheckBoxA.Checked == true)
{
answer = "A";
}
if (CheckBoxB.Checked == true)
{
if (!string.IsNullOrEmpty(answer))
{
answer = answer + "," + "B";
}
else
{
answer = "B";
}
}
if (CheckBoxC.Checked == true)
{
if (!string.IsNullOrEmpty(answer))
{
answer = answer + "," + "C";
}
else
{
answer = "C";
}
}
if (CheckBoxD.Checked == true)
{
if (!string.IsNullOrEmpty(answer))
{
answer = answer + "," + "D";
}
else
{
answer = "D";
}
}
}
//if (((CheckBox)FormView1.FindControl("CheckBoxA")).Checked == true)
//{
// Jscript.Alert("ok");
//}
string id = ((Label)FormView1.Controls[0].FindControl("Label2")).Text;
Tissues.Rows.Add(int.Parse(id), answer);
Jscript.Alert(id + "," + answer + "," + CheckBox1.Checked.ToString()); CheckBoxA.Checked = false;
CheckBoxB.Checked = false;
CheckBoxC.Checked = false;
CheckBoxD.Checked = false; }
else
{
((Label)FormView1.Controls[0].FindControl("Label3")).Text = (currentPage + 1).ToString();
lnkDown.Visible = false; //顯示完不顯示,而顯示提交按鈕
this.Button1.Visible = true;
// Jscript.Alert("end");
Session.Add("Tissues", Tissues);
//(DataTable)Session["Tissues"] = Tissues;
string id = ((Label)FormView1.Controls[0].FindControl("Label2")).Text; if (Tissues.Rows.Count > 0)
{
Jscript.Alert(Tissues.Rows[0][0].ToString());
}
} }
else
{
Jscript.Alert("還沒有添加試題");
return;
} // FormView1.DataSource = vIPExamQuestionsBLL.SelectVipQuestionsExamProjectDisplay(1);
// FormView1.DataBind();
}
else
{
Jscript.Alert("沒有查找相關關項目的數據!");
return;
} } }
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void FormView1_PageIndexChanging(object sender, FormViewPageEventArgs e)
{
//FormView1.DataSource=getdatatable(vIPExamQuestionsBLL.SelectVipQuestionsExamProjectDisplay(int.Parse(examProjectId))).DefaultView;
//FormView1.DataBind();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
if (FormView1.PageIndex == fcount)
{
Jscript.Alert("end");
DataTable table = Session["Tissues"] as DataTable; if (table.Rows.Count>0)
{ //read table and push in Sqlserver
Jscript.Alert(table.Rows[0][0].ToString());
}
else
{
//session either expired or invalid page being accessed.
}
}
} /// <summary>
///
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
private DataTable getdatatable(DataTable table)
{
if (!object.Equals(table, null))//
{
DataTable tableDec = new DataTable(); #region ExamQuestionsProject,ExamQuestionsTitle,ExamQuestionsA,ExamQuestionsB,ExamQuestionsC,ExamQuestionsD,ExamQuestionsAnswer,ExamQuestionsDesc,ExamProjectTitle
tableDec.Columns.Add("ExamQuestionsID", typeof(int));
tableDec.Columns.Add("ExamQuestionsProject", typeof(int));
tableDec.Columns.Add("ExamQuestionsTitle", typeof(string));
tableDec.Columns.Add("ExamQuestionsA", typeof(string));
tableDec.Columns.Add("ExamQuestionsB", typeof(string));
tableDec.Columns.Add("ExamQuestionsC", typeof(string));//在職狀態
tableDec.Columns.Add("ExamQuestionsD", typeof(string));
tableDec.Columns.Add("ExamQuestionsAnswer", typeof(string));
tableDec.Columns.Add("ExamQuestionsDesc", typeof(string));
tableDec.Columns.Add("ExamProjectTitle", typeof(string));
tableDec.Columns.Add("ExamProjectCheck", typeof(bool)); #endregion
foreach (DataRow row in table.Rows) // Loop over the rows.
{ bool check = false;
tableDec.Rows.Add(row["ExamQuestionsID"], row["ExamQuestionsProject"], row["ExamQuestionsTitle"], row["ExamQuestionsA"], row["ExamQuestionsB"], row["ExamQuestionsC"], row["ExamQuestionsD"], row["ExamQuestionsAnswer"], row["ExamQuestionsDesc"], row["ExamProjectTitle"], check); } return tableDec;
}
else
{
return null;
} //DataColumn col = new DataColumn("check", typeof(bool));
//dt.Columns.Add(col);
////dt.Columns.AddRange(col);
////dt.Columns.AddRange("check", typeof(bool)); //for (int i=0;i<dt.Rows.Count;i++)
//{
// DataRow row = dt.NewRow();
// row["check"] = false;
// dt.Rows.Add(row);
//} ////for(int i=0;i<dt.Rows.Count;i++)
////{ ////}
//return dt;
}
}

Datatable paging,Repeater with Paging的更多相关文章

  1. [转]Efficiently Paging Through Large Amounts of Data

    本文转自:http://msdn.microsoft.com/en-us/library/bb445504.aspx Scott Mitchell April 2007 Summary: This i ...

  2. 前端paging分页,前端设置每页多少条和当前页面的索引,传给后端,数据显示出来

    1.首先引入jquery 2.在引入paging.css和paging.js  这2个我存在百度云上: 链接:https://pan.baidu.com/s/1SPxlBkkx-pNAtLuRLifE ...

  3. [转]Paging, Searching and Sorting in ASP.Net MVC 5

    本文转自:http://www.c-sharpcorner.com/UploadFile/4b0136/perform-paging-searching-sorting-in-Asp-Net-mvc- ...

  4. Jetpack系列:Paging组件帮你解决分页加载实现的痛苦

    相信很多小伙伴们在项目实战中,经常会用到界面的分页显示.加载更多等功能.需要针对具体功能做针对性开发和调试,耗时耗力. Paging组件的使用将这部分的工作简化,从而让开发者更专注于业务的具体实现.下 ...

  5. Elasticsearch系列---搜索分页和deep paging问题

    概要 本篇从介绍搜索分页为起点,简单阐述分页式数据搜索与原有集中式数据搜索思维方式的差异,就分页问题对deep paging问题的现象进行分析,最后介绍分页式系统top N的案例. 搜索分页语法 El ...

  6. ES 25 - Elasticsearch的分页查询及其深分页问题 (deep paging)

    目录 1 分页查询方法 2 分页查询的deep paging问题 1 分页查询方法 在GET请求中拼接from和size参数 // 查询10条数据, 默认从第0条数据开始 GET book_shop/ ...

  7. LINQ查询返回DataTable类型

    个人感觉Linq实用灵活性很大,参考一篇大牛的文章LINQ查询返回DataTable类型 http://xuzhihong1987.blog.163.com/blog/static/267315872 ...

  8. WPF DataGrid分页功能实现代码 修改原作者不能实现的部分

    这两天需要给Datagrid加个分页,查找了一些相关的文章,发现有一个写了一个控件比较好,地址是 http://blog.csdn.net/zdw_wym/article/details/822189 ...

  9. Oracle分页存储过程

    1.在oracle的sqlplus或其他工具中运行一下pl/sql块建立存储过程 --创建包create or replace package testpackage astype test_curs ...

随机推荐

  1. 【spring】 SpringMVC返回json数据的三种方式

    配置方法一 **1.导入第三方的jackson包,jackson-mapper-asl-1.9.7.jar和jackson-core-asl-1.9.7.jar. 2.spring配置文件添加** & ...

  2. inspect模块---检查活动对象

    inspect模块提供了一些有用的函数来帮助获取有关活动对象(如模块,类,方法,函数,跟踪,框架对象和代码对象)的信息.例如,它可以帮助您检查类的内容,检索方法的源代码,提取和格式化函数的参数列表,或 ...

  3. 大型php网站性能和并发访问优化方案(转载自php中文网)

               网站性能优化对于大型网站来说非常重要,一个网站的访问打开速度影响着用户体验度,网站访问速度慢会造成高跳出率,小网站很好解决,那对于大型网站由于栏目多,图片和图像都比较庞大,那该怎 ...

  4. 4、numpy+pandas速查手册

    <Python数据分析常用手册>一.NumPy和Pandas篇 一.常用链接: 1.Python官网:https://www.python.org/2.各种库的whl离线安装包:http: ...

  5. 洛谷 P1546 最短网络 Agri-Net(最小生成树)

    嗯... 题目链接:https://www.luogu.org/problemnew/show/P1546 首先不难看出这道题的思想是用了最小生成树,但是这道题有难点: 1.读题读不明白 2.不会读入 ...

  6. Qt 学习之路 2(30):Graphics View Framework

    Qt 学习之路 2(30):Graphics View Framework 豆子 2012年12月11日 Qt 学习之路 2 27条评论 Graphics View 提供了一种接口,用于管理大量自定义 ...

  7. css类选择器中 空格 逗号 啥都不填的区别及其他笔记

    .a.b 代表 一个元素上 同时 有 a 类 和 b 类 .a .b (中间有空格) 代表 .b 是 .a 的子元素选择. .a,.b 代表 class='a' 和 class='b' 都会被选择上.

  8. 基于中间件的RBAC权限控制

    RBAC 是什么 RBAC(Role-Based Access Control,基于角色的访问控制),就是用户通过角色与权限进行关联. 在 Django 中,权限就是用户对一个包含正则表达式 url ...

  9. UVA - 10780 唯一分解定理

    白书P171 对m,n!分解,质因子指数取min #include<iostream> #include<algorithm> #include<cstdio> # ...

  10. 1093 字符串A+B (20 分)

    给定两个字符串 A 和 B,本题要求你输出 A+B,即两个字符串的并集.要求先输出 A,再输出 B,但重复的字符必须被剔除. 输入格式: 输入在两行中分别给出 A 和 B,均为长度不超过 10​6​​ ...