您的位置:首页 > 编程语言 > ASP

asp.net学习之扩展GridView

2010-09-17 13:56 295 查看
本节讨论如何从现有的控件,进而扩展成强大的,更定制的GridView控件

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.待续…

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: