社区
Windows客户端开发
帖子详情
ObjectList控件的自定义分页怎么写?
wdbxm
2007-01-29 07:19:05
请问这个控件的自定义分页怎么写啊?LoadItem()事件怎么写啊?望高手指点?(绑定DataReader)
可以给我一个简单的例子吗?谢谢~~
...全文
390
2
打赏
收藏
ObjectList控件的自定义分页怎么写?
请问这个控件的自定义分页怎么写啊?LoadItem()事件怎么写啊?望高手指点?(绑定DataReader) 可以给我一个简单的例子吗?谢谢~~
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
jazzking746
2007-01-29
打赏
举报
回复
利用DataTable自身的Select方法,传入起始值,读取指定行数记录,最终实现翻页效果
/// <summary>
/// 读取指定ID段内的Mail
/// </summary>
/// <param name="startID">DataTable中开始记录的ID</param>
/// <returns></returns>
private void SelectTable(int startID)
{
try
{
DataTable dtAllData = this._dtAllData;
DataTable dtSelectData = new DataTable();
dtSelectData.Columns.Add("ProductID",typeof(String));
dtSelectData.Columns.Add("ProductName",typeof(String));
string strExpr;
int endID = startID + GlobalConfig.Size;
if(startID == 0)
{
strExpr = "ProductID >= "+ startID +" and ProductID <= "+ endID +"";
}
else
{
strExpr = "ProductID >= "+ startID +" and ProductID < "+ endID +"";
}
if(dtAllData != null && dtAllData.Rows.Count > 0)
{
DataRow[] foundRows = dtAllData.Select(strExpr);
string flag1 = foundRows.Length.ToString();
for(int i = 0; i < foundRows.Length; i ++)
{
DataRow row = dtSelectData.NewRow();
row["ProductID"] = foundRows[i][0];
row["ProductName"] = foundRows[i][1];
dtSelectData.Rows.Add(row);
}
if(dtSelectData != null && dtSelectData.Rows.Count > 0)
{
this.List.DataSource = dtSelectData;
this.List.DataBind();
}
try
{
DataTable dtPage = GetPage();
string selectPage = Page.Request["SelectPage"];
for(int i = 0; i < dtPage.Rows.Count; i++)
{
Link link = new System.Web.UI.MobileControls.Link();
if(i == Convert.ToInt32(selectPage))
{
link.Text = "[本页" + dtPage.Rows[i][0].ToString() + "]";
}
else
{
link.Text = "[" + dtPage.Rows[i][0].ToString() + "]";
}
link.NavigateUrl = dtPage.Rows[i][1].ToString();
link.ID = i.ToString();
link.BreakAfter = false;
this.Panel.Controls.Add(link);
}
}
catch(Exception exc)
{
this.lblMessage.Text = exc.Message;
}
}
else
{
this.lblMessage.Text = "没有记录!";
this.lblMessage.Visible = true;
}
}
catch(Exception exc)
{
this.lblMessage.Text = exc.Message;
}
}
#endregion
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.dataSet11 = new WapPager.DataSet1();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT ProductID, ProductName FROM Products";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO Products(ProductName) VALUES (@ProductName); SELECT ProductID, Produc" +
"tName FROM Products WHERE (ProductID = @@IDENTITY)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductName", System.Data.SqlDbType.NVarChar, 40, "ProductName"));
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = "UPDATE Products SET ProductName = @ProductName WHERE (ProductID = @Original_Produ" +
"ctID) AND (ProductName = @Original_ProductName); SELECT ProductID, ProductName F" +
"ROM Products WHERE (ProductID = @ProductID)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductName", System.Data.SqlDbType.NVarChar, 40, "ProductName"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProductID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProductID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProductName", System.Data.SqlDbType.NVarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProductName", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.Int, 4, "ProductID"));
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = "DELETE FROM Products WHERE (ProductID = @Original_ProductID) AND (ProductName = @" +
"Original_ProductName)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProductID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProductID", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProductName", System.Data.SqlDbType.NVarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProductName", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "server=127.0.0.1;database=Northwind;uid=sa;pwd=sa;timeout=300;";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Products", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("ProductID", "ProductID"),
new System.Data.Common.DataColumnMapping("ProductName", "ProductName")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
}
jazzking746
2007-01-29
打赏
举报
回复
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
this._dtAllData = GetAllData();
SelectTable(Convert.ToInt32(Page.Request["startID"]));
}
}
#endregion
#region 获取全部数据,返回DataTable
/// <summary>
///GetAllData是获取全部数据,返回DataTable的方法,之所以采用DataTable来存放全部数
///据,主要是为了后面用DataTable的Select方法来获取其中指定范围内记录,你可以从多
///种途径获取这个DataTable,比如WebService等等;
/// </summary>
private DataTable GetAllData()
{
this.sqlDataAdapter1.Fill(this.dataSet11);
return this.dataSet11.Tables["Products"];
}
#endregion
#region 通过数据总数、每页规定显示数量,计算出页数的方法
/// <summary>
/// GetPage是通过数据总数、每页规定显示数量,计算出页数的方法,返回存放全部页码的
/// DataTable,我们为这个DataTable定义了LinkText和LinkUrl两列,这两列的值供页码
/// 控件Link绑定数据所用。
/// </summary>
private DataTable GetPage()
{
DataTable dtPage = new DataTable();
DataTable dtAllData = this._dtAllData;
int dataCount = dtAllData.Rows.Count;
int pageCount = 0;
if((dataCount%GlobalConfig.Size) == 0)
{
pageCount = dataCount/GlobalConfig.Size;
}
if((dataCount%GlobalConfig.Size) != 0)
{
pageCount = dataCount/GlobalConfig.Size + 1;
}
dtPage.Columns.Add("LinkText",typeof(String));
dtPage.Columns.Add("LinkUrl",typeof(String));
for(int i = 0;i < pageCount; i++)
{
DataRow row = dtPage.NewRow();
row["LinkText"] = i + 1;
if(i == 0)
{
row["LinkUrl"] = "MobileWebForm1.aspx?startID=" + ((i*GlobalConfig.Size)) + "&selectPage=" + i;
}
else
{
row["LinkUrl"] = "MobileWebForm1.aspx?startID=" + ((i*GlobalConfig.Size) + 1) + "&selectPage=" + i;
}
dtPage.Rows.Add(row);
}
return dtPage;
}
ASP.NET
控件
的使用
14.2.1 创建
自定义
分页
用户界面 458 14.2.2 使用DataPager
控件
进行数据源
分页
459 14.3 小结 461 第四部分 创建组件 第15章 创建组件 464 15.1 创建基本组件 464 15.1.1 组件和动态编译 466 15.1.2 App_Code文件夹...
net实用类50个常用方法升级版
分页
///DataBindCheckBox
List
()CheckBox
List
控件
绑定 ///ElseIpAddr()调用此方法 返回当前登录的省市IP地址 ///ElseDataTimeIng()返回本地电脑的当前日期的年月日时分秒 动态的显示 JS实现 ///ElsePageLoad()页面...
ASP.NET.4揭秘
14.2.1 创建
自定义
分页
用户界面524 14.2.2 使用datapager
控件
进行数据源
分页
526 14.3 小结527 第15章 使用chart
控件
528 15.1 chart
控件
的基础知识528 15.1.1 使用chart
控件
显示数据528 15.1.2 排序和过滤数据532 ...
C#编程经验技巧宝典
85 <br>0130 复制字符串中指定的字符 85 <br>0131 巧截字符串的数字 86 <br>0132 如何存储变长字符串 86 <br>0133 在进行字符串比较时忽略大小
写
87 <br>0134 如何去除字符串尾空格 87 ...
JAVA上百实例源码以及开源项目
Java生成
自定义
控件
源代码 2个目标文件 Java实现HTTP连接与浏览,Java源码下载 1个目标文件 摘要:Java源码,网络相关,HTTP Java实现HTTP连接与浏览,Java源码下载,输入html文件地址或网址,显示页面和HTML源文件...
Windows客户端开发
7,655
社区成员
18,845
社区内容
发帖
与我相关
我的任务
Windows客户端开发
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
复制链接
扫一扫
分享
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章