asp.net学习之扩展GridView
2010-09-17 13:56
295 查看
本节讨论如何从现有的控件,进而扩展成强大的,更定制的GridView控件
例1: 创建长文本字段
===App_code\myControls.cs===
Code
public class DeleteButtonField : ButtonField
{
private string _confirmMessage = "确认要删除吗?";
public string ConfirmMessage
{
get { return _confirmMessage; }
set { _confirmMessage = value; }
}
// 默认情况下,作为删除按钮,按钮上显示删除字样
public DeleteButtonField()
{
this.CommandName = "Delete";
this.Text = "删除";
}
public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
{
base.InitializeCell(cell, cellType, rowState, rowIndex);
if(cellType==DataControlCellType.DataCell) //如果是数据Cell
{
WebControl button = (WebControl)cell.Controls[0];
button.Attributes["onclick"] = String.Format("return confirm('{0}');", _confirmMessage);
}
}
}
1.扩展BoundField
默认的BoundField不能显示多文本,文字一多,就会扩大整个Table的Height值,解决这个问题的方法可以通过TemplateField加入Div控件来解决,但是,也可以从BoundField类上进行扩展,加入一点特有的功能,让他能够显示多文本例1: 创建长文本字段
===App_code\myControls.cs===
Code
public class DeleteButtonField : ButtonField
{
private string _confirmMessage = "确认要删除吗?";
public string ConfirmMessage
{
get { return _confirmMessage; }
set { _confirmMessage = value; }
}
// 默认情况下,作为删除按钮,按钮上显示删除字样
public DeleteButtonField()
{
this.CommandName = "Delete";
this.Text = "删除";
}
public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
{
base.InitializeCell(cell, cellType, rowState, rowIndex);
if(cellType==DataControlCellType.DataCell) //如果是数据Cell
{
WebControl button = (WebControl)cell.Controls[0];
button.Attributes["onclick"] = String.Format("return confirm('{0}');", _confirmMessage);
}
}
}
3.待续…
相关文章推荐
- asp.net学习之扩展GridView
- asp.net学习之扩展GridView
- asp.net学习之扩展GridView
- ASP.Net MVC开发基础学习笔记(2):HtmlHelper与扩展方法
- 黑马程序员之 ASP.NET学习笔记:GridView控件的常用属性及方法
- ASP.NET学习笔记2--自己写代码绑定Gridview
- 扩展ASP.NET 2.0内置GridView控件之一第三页
- UpdatePanel中GridView的分页问题 GridView中的超链接 (输入一半带提示功能)ASP.NET AJAX Control Toolkit 新扩展特性:AutoCompleteExtender
- ASP.NET 3.5核心编程学习笔记(55):自定义扩展程序控件的创建
- Asp.Net Ajax 学习笔记10 JavaScript的原生类型以及Microsoft AJAX Library的相关扩展(下)
- ASP.NET学习资料三 ASP.NET页面扩展名
- 【学习笔记】〖ASP.NET〗GridView中HyperLinkField的控制
- Asp.Net Ajax 学习笔记16 Profile Service扩展方式
- Asp.Net Ajax 学习笔记12 基于Microsoft AJAX Library扩展客户端组件
- asp.net 学习之路之gridView控件之修改数据
- Asp.Net Ajax 学习笔记14 扩展Microsoft AJAX Library的异步通信层
- ASP.Net MVC开发基础学习笔记(2):HtmlHelper与扩展方法
- asp.net学习旅程5(GridView特别篇,上)
- 系统学习asp.net Ajax中GridView、UpdatePanel、UpdateProgress、Timer使用
- ASP.NET学习系列(五)开始控件之旅之TextBox及其Ajax扩展控件