public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex) { string index = rowIndex.ToString(); if (cellType == DataControlCellType.DataCell) { IDataControlButton btn = DataControlButton.CreateButton(ButtonType, Control, Text, ImageUrl, CommandName, index, false); if (CausesValidation) { btn.Container = null; btn.CausesValidation = true; btn.ValidationGroup = ValidationGroup; } if (!String.IsNullOrEmpty(DataTextField)) { if ((rowState & DataControlRowState.Insert) == 0) { cell.DataBinding += new EventHandler(OnDataBindField); } } cell.Controls.Add((Control)btn); } else { base.InitializeCell(cell, cellType, rowState, rowIndex); } }
void OnDataBindField(object sender, EventArgs e) { DataControlFieldCell cell = (DataControlFieldCell)sender; IDataControlButton btn = (IDataControlButton)cell.Controls [0]; btn.Text = FormatDataTextValue(GetBoundValue(cell.BindingContainer)); }
Control CreateButton(string text, string image, string command, string arg) { IDataControlButton c = DataControlButton.CreateButton(ButtonType, Control, text, image, command, arg, false); if (CausesValidation) { if (command == DataControlCommands.UpdateCommandName || command == DataControlCommands.InsertCommandName) { c.Container = null; c.CausesValidation = true; c.ValidationGroup = ValidationGroup; } } return((Control)c); }