当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > ASP.NET的Web controls(二)

ASP.NET
动态加载Js代码到Head标签中的脚本
asp.net Parameters.AddWithValue方法在SQL语句的 Where 字句中的用法
ASP.NET 运行时错误: 没有为扩展名“.asax”注册的生成提供程序修正版
Convert.ToInt32与Int32.Parse区别及Int32.TryParse
WebService出现"因 URL 意外地以 结束,请求格式无法识别"的解决方法
asp.net(C#) Xml操作(增删改查)练习
asp.net 分页sql语句(结合aspnetpager)
asp.net开发与web标准的冲突问题的一些常见解决方法
asp.net Repeater中使用if的代码
Asp.net FCKEditor 2.6.3 上传文件没有权限解决方法
C# 命名规则(挺不错的)
asp.net 动态生成控件并获取其值
使用DataGrid中扩展ItemRenderer和HeaderRenderer进行操作
asp.net Hashtable 遍历写法
asp.net GridView和DataList实现鼠标移到行行变色
C# 邮件地址是否合法的验证
.net发送邮件实现代码
ASP.Net 上传图片并生成高清晰缩略图
asp.net 事件与委托分析
C# 无限级分类的实现

ASP.NET的Web controls(二)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 136 ::
收藏到网摘: n/a

crystal译·yesky

  也许在这个新的 controls中最有趣的莫过于 DataGrid。Datagrid是一个多列的数据绑定网格,通过它你可以轻而易
举的将数据置于其中。它同时提供分页、排序等所有你所期望的功能。我们看一个Datagrid的例子.

  注:我们将在另外的文章里介绍Datagrid的属性和方法。

<%@ Page language="C#" src="DataGrid.cs" inherits="Samples.DataGridPage"%>
...

<asp:DataGrid runat=server id="titlesGrid">
</asp:DataGrid>

  上面的 .aspx 文件显示在不设置 DataGrid 控件任何属性的情况下对其进行声明。

DataGrid.cs:

namespace Samples {
...

public class DataGridPage : Page {
protected DataGrid titlesGrid;

public ICollection GetTitlesList() {

// 从在应用程序状态中高速缓存的 DataSet 中检索标题列表。
DataSet titlesDataSet = (DataSet)Application["TitlesDataSet"];

if (titlesDataSet != null) {
return titlesDataSet.Tables["Title"].DefaultView;
}
else {
return null;
}
}

private void LoadTitlesGrid() {

// 从数据库中检索数据
ICollection titlesList = GetTitlesList();

// 设置控件的数据源
titlesGrid.DataSource = titlesList;

// 并使它用此数据源构建其项目
titlesGrid.DataBind();
}

protected override void OnLoad(EventArgs e) {
base.OnLoad(e);

if (!IsPostBack) {

// 首次请求此页
LoadTitlesGrid();
}
}
}
}

  记录丢失,对于程序员来说是一个非常严重的事情。在新的系统中, 中心对象是Dataset。它与recordset相类似,是
数据内在存储记忆的副本。Dataset对于您的开发来说是中心所在,但是现在,我只能说它只是相近与XML,使程式在简单
化和统一化的过程中,相对简单。你还是可以用你过去用过的来处理一切…(除了服务器端游标)…