ASP.NET服务器控件数据绑定总结
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;//
using System.Data.SqlClient;
using System.Data;//
using System.Web.UI;//
using Wuqi.Webdiyer;//此控件请在网上下载 namespace Study
{
public sealed class WebControlsBind
{
#region DropDownlist 绑定
/// <summary>
/// 绑定DropDownList控件
/// </summary>
/// <param name="p_ddlControl">控件</param>
/// <param name="p_drSource">数据源</param>
/// <param name="p_strText">文本值</param>
/// <param name="p_strValue">值</param>
/// <param name="p_blAll">是否包含全部项,若不包含返回false,若包含返回true</param>
public static void BindDDL(DataTable p_drSource, DropDownList p_ddlControl, string p_strText, string p_strValue, bool p_blAll)
{
p_ddlControl.DataSource = p_drSource;
p_ddlControl.DataTextField = p_strText;
p_ddlControl.DataValueField = p_strValue;
p_ddlControl.DataBind();
if (p_blAll == true)
{
ListItem li = new ListItem("全部", "");
p_ddlControl.Items.Insert(, li);//使用add方法只能添加到最后,使用Insert方法可以添加到指定的位置 }
} #endregion #region 带分页的数据绑定Repeater控件
/// <summary>
/// 带分页的Repeater的数据绑定
/// </summary>
/// <param name="dsSource">数据源</param>
/// <param name="rpt">Repeater控件</param>
/// <param name="anp">分页控件</param>
public static void Bindrpt(DataTable dsSource, Repeater rpt, AspNetPager anp)
{
DataView dv = dsSource.DefaultView;
anp.RecordCount = dv.Count;
if (dv.Count > )
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dv;
pds.AllowPaging = true;
pds.CurrentPageIndex = anp.CurrentPageIndex - ;
pds.PageSize = anp.PageSize;
rpt.DataSource = pds;
rpt.DataBind(); } }
public static void Bindrpt(DataTable dsSource, Repeater rpt, AspNetPager anp,string order)
{
DataView dv = dsSource.DefaultView;
dv.Sort = order;
DataTable dt = dv.ToTable();
anp.RecordCount = dv.Count;
if (dv.Count > )
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dv;
pds.AllowPaging = true;
pds.CurrentPageIndex = anp.CurrentPageIndex - ;
pds.PageSize = anp.PageSize;
rpt.DataSource = pds;
rpt.DataBind(); } } #endregion
#region 带分页的数据绑定Datalist控件
/// <summary>
/// 带分页的Repeater的数据绑定
/// </summary>
/// <param name="dsSource">数据源</param>
/// <param name="dlt">DataList控件</param>
/// <param name="anp">分页控件</param>
public static void BindDlt(DataTable dsSource, DataList dlt, AspNetPager anp)
{
DataView dv = dsSource.DefaultView;
anp.RecordCount = dv.Count;
if (dv.Count > )
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dv;
pds.AllowPaging = true;
pds.CurrentPageIndex = anp.CurrentPageIndex - ;
pds.PageSize = anp.PageSize;
dlt.DataSource = pds;
dlt.DataBind(); } } #endregion }
}
ASP.NET服务器控件数据绑定总结的更多相关文章
- ASP.NET 前端数据绑定---<%#%>及Eval()的使用
ASP.NET 前端html代码中会经常出现的<%%>的代码,里面的文本其实就是不能直接输出到客户端浏览器的文本,是需要服务器解释的. 在ASP中,<%%>里面的文本是vbsc ...
- js 操作ASP.NET服务器控件
js 操作ASP.NET服务器控件 在ASP.NET中使用js时,js获取DOM元素时,经常获取不到,这是因为获取的方法有误,现在介绍一方法,解决如何使用js获取ASP.NET控件在浏览器端生成htm ...
- 【转】【Asp.Net】asp.net服务器控件创建
VS新建一个Web服务控件工程,会默认生成以下代码: namespace WebControlLibrary { [DefaultProperty("Text")] [Toolbo ...
- JQuery EasyUI弹出对话框解决Asp.net服务器控件无法执行后台代码的方法(转)
原文:JQuery EasyUI弹出对话框解决Asp.net服务器控件无法执行后台代码的方法 jquery-easyui是一个基于jquery的图形界面插件,利用easyui可以创建很多好看的网页界面 ...
- ASP.NET服务器控件对应的HTML标签
了解ASP.NET的控件最终解析成什么HTML代码,有助于我们对ASP.NET更深的了解,在使用JS交互时也知道如何操作. ASP.NET 服务器控件渲染到客户端之后对应的HTML标签讲解. labe ...
- 【转】ASP.NET常用数据绑定控件优劣总结
转自:http://www.cnblogs.com/Olive116/archive/2012/10/24/2736570.html ASP.NET常用数据绑定控件优劣总结 本文的初衷在于对Asp ...
- Asp.net服务器控件在IE10下的不兼容问题
Asp.net服务器控件在IE10下的不兼容问题 时间:2013-05-16 09:07点击: 89 次 [大 中 小] 相信很多使用IE10的童鞋们已经发现了这个问题,以下是本人在IE10标准模式下 ...
- asp.net服务器控件防止多次提交问题
用户可能点击多次提交按钮.这样,导致向数据库中插入了多条相同的记录. 好像这2个方法都是针对的服务器控件! //方法一:在提交时调用一段客户端的代码. function a() { document. ...
- 向ASP.NET服务器控件中嵌入CSS资源
Step1:于[项目解决方案]中右键新建[ASP.NET服务器控件]项目 Step2:于项目中添加[Resources]文件夹,于该文件夹下添加[CSS文件] Step3:单击该CSS文件,并将[属性 ...
随机推荐
- nuget.exe the application could not be started
http://stackoverflow.com/questions/5730412/error-when-running-the-nuget-exe-command Ok, so this turn ...
- [HDOJ5542]The Battle of Chibi(DP,树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5542 题意:n个数中找m个数,使得从左到右读是上升的子序列.问一共有多少种. dp(i,j)表示取到第 ...
- debian attempt to kill init!
之前想在debian下安装Oracle 11g,结果在安装之前要安装好多的依赖包. 在centos和redhat下可以很方便的使用yum来安装,哗啦啦一下全装完了, 后来我在debian下用apt-g ...
- 数据引用Data References
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- CSS笔记(十五)CSS3之用户界面
参考:http://www.w3school.com.cn/css3/css3_user_interface.asp 在 CSS3 中,新的用户界面特性包括重设元素尺寸.盒尺寸以及轮廓等. 新的用户界 ...
- CSS笔记(四)文本
CSS 文本属性可定义文本的外观.通过文本属性,可以改变文本的颜色.字符间距,对齐文本,装饰文本和对文本进行缩进,等等. 参考:http://www.w3school.com.cn/css/css_t ...
- Shell Sort(草稿)
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Shel ...
- elcipse 安装svn插件 转载
1.下载最新的Eclipse,我的版本是3.7.2 indigo(Eclipse IDE for Java EE Developers)版 如果没有安装的请到这里下载安装:http://ecli ...
- jsp get方式请求参数中包含中文乱码问题解决
1. 自己接收到参数之后在后台进行转码处理 2: 修改tomcat的配置文件 server.xml <Connector port="8080" protocol=&quo ...
- PHP爬虫抓取网页内容 (simple_html_dom.php)
使用simple_html_dom.php,下载|文档 因为抓取的只是一个网页,所以比较简单,整个网站的下次再研究,可能用Python来做爬虫会好些. <meta http-equiv=&quo ...