Sep 262006
 

[code=c#]
public class LimitedBoundField : BoundField
{
private int _characterLimit = 0;
public int CharacterLimit
{
get { return _characterLimit; }
set { _characterLimit = value; }
}
public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
{
base.InitializeCell(cell, cellType, rowState, rowIndex);
if (rowState == DataControlRowState.Edit && cellType == DataControlCellType.DataCell)
{
TextBox tb = ((TextBox)cell.Controls[0]);
tb.MaxLength = _characterLimit;
tb.Text = tb.Text.Substring(0, (tb.Text.Length > _characterLimit) ? _characterLimit : tb.Text.Length);
}
}
} [/code]

Today on history:

  1. 2009:  周公解梦 —— 梦见熊猫(0)
 Posted by at 9:08 am

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)