Adds text or controls to a cell's controls collection.
Assembly: System.Web (in System.Web.dll)
'Declaration Public Overridable Sub InitializeCell ( _ cell As DataControlFieldCell, _ cellType As DataControlCellType, _ rowState As DataControlRowState, _ rowIndex As Integer _ )
- Type: System.Web.UI.WebControls.DataControlFieldCell
- Type: System.Web.UI.WebControls.DataControlRowState
Types derived from DataControlField implement the method to add text and controls to a DataControlFieldCell object that belongs to a data control that uses tables to display a user interface (UI). These data controls create the complete table structure row by row when their respective CreateChildControls methods are called. The method is called by the InitializeRow method of data controls such as DetailsView and GridView.
Call this method when you are writing a custom data-bound control that uses DataControlFieldCell objects to initialize the cells of the table structure with data or controls. Implement this method when you are writing a class derived from DataControlField.
The following code example demonstrates how to implement the method for a control that derives from the DataControlField class. The RadioButtonField class renders a data-bound radio button for every row in a GridView control. When the row is displaying data to a user and is not in edit mode, the RadioButton control is disabled. When the row is in edit mode, for example when the user chooses to update a row in the GridView control, the RadioButton control is rendered as enabled so that it can be clicked. This example uses bitwise AND operators, because the row state might be a combination of one or more DataControlRowState values.
' This method adds a RadioButton control and any other ' content to the cell's Controls collection. Protected Overrides Sub InitializeDataCell( _ ByVal cell As DataControlFieldCell, _ ByVal rowState As DataControlRowState) Dim radio As New RadioButton() ' If the RadioButton is bound to a DataField, add ' the OnDataBindingField method event handler to the ' DataBinding event. If DataField.Length <> 0 Then AddHandler radio.DataBinding, AddressOf Me.OnDataBindField End If radio.Text = Me.Text ' Because the RadioButtonField is a BoundField, it only ' displays data. Therefore, unless the row is in edit mode, ' the RadioButton is displayed as disabled. radio.Enabled = False ' If the row is in edit mode, enable the button. If (rowState And DataControlRowState.Edit) <> 0 _ OrElse (rowState And DataControlRowState.Insert) <> 0 Then radio.Enabled = True End If cell.Controls.Add(radio) End Sub