Class RowSelectorColumn

A System.Web.UI.WebControls.DataGridColumn which shows a checkbox in each row to signal the selection of that row.

Inheritance
System.Object
RowSelectorColumn
Namespace: Mediachase.Web.Console.Controls
Assembly: Mediachase.WebConsoleLib.dll
Version: 10.8.0
Syntax
public class RowSelectorColumn : DataGridColumn
Examples

This example shows the use of this column in a simple System.Web.UI.WebControls.DataGrid

<%@ Import Namespace="System.Data" %>
<%@ Register TagPrefix="mbrsc" Namespace="MetaBuilders.WebControls" Assembly="MetaBuilders.WebControls.RowSelectorColumn" %>

<html>
   <script language="C#" runat="server">

      ICollection CreateDataSource() 
      {
         DataTable dt = new DataTable();
         DataRow dr;

         dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
         dt.Columns.Add(new DataColumn("StringValue", typeof(string)));

         for (int i = 0; i < 5; i++) 
         {
            dr = dt.NewRow();

            dr[0] = i;
            dr[1] = "Item " + i.ToString();

            dt.Rows.Add(dr);
         }

         DataView dv = new DataView(dt);
         return dv;
      }

      void Page_Load(Object sender, EventArgs e) 
      {

         if (!IsPostBack) 
         {
            // Load this data only once.
            ItemsGrid.DataSource= CreateDataSource();
            ItemsGrid.DataBind();
         }
      }

      protected void ShowSelections( Object sender, EventArgs e ) {
		RowSelectorColumn rsc = ItemsGrid.Columns[0] as RowSelectorColumn;
		Message.Text = "Total selected rows = " + rsc.SelectedIndexes.Length.ToString() + "<br>";
		foreach( Int32 selectedIndex in rsc.SelectedIndexes ) {
			Message.Text += selectedIndex.ToString() + "<br>";
		}
      }

   </script>

<body>

   <form runat=server>

      <h3>DataGrid Example</h3>

      <asp:DataGrid id="ItemsGrid"
           BorderColor="black"
           BorderWidth="1"
           CellPadding="3"
           AutoGenerateColumns="true"
           runat="server">

         <HeaderStyle BackColor="darkblue" forecolor="white">
         </HeaderStyle> 
         <Columns>
			<mbrsc:RowSelectorColumn allowselectall="true" />
         </Columns>

      </asp:DataGrid>

      <asp:Button runat="server" onclick="ShowSelections" text="Show Selections" />
      <br>
      <asp:Label runat="server" id="Message" />

   </form>

</body>
</html>

Constructors

RowSelectorColumn()

Creates a new instance of the RowSelectorColumn control.

Declaration
public RowSelectorColumn()

Properties

AllowSelectAll

Gets or sets the behavior of including a checkbox in the Header area which selects all the row checkboxes based on its value.

Declaration
public virtual bool AllowSelectAll { get; set; }
Property Value
Type Description
System.Boolean

true if [allow select all]; otherwise, false.

Remarks

This behavior will only exist on browsers supporting javascript and the W3C DOM.

AutoPostBack

Gets or sets if the column's controls will postback automaticly when the selection changes.

Declaration
public virtual bool AutoPostBack { get; set; }
Property Value
Type Description
System.Boolean

true if [auto post back]; otherwise, false.

ScriptPath

Gets or sets the script path.

Declaration
public virtual string ScriptPath { get; set; }
Property Value
Type Description
System.String

The script path.

SelectAllControl

Gets the checkbox appearing in the header row which controls the other checkboxes.

Declaration
protected virtual HtmlInputCheckBox SelectAllControl { get; }
Property Value
Type Description
System.Web.UI.HtmlControls.HtmlInputCheckBox

The select all control.

Remarks

The checkbox if AllowSelectAll is true, otherwise null.

SelectedIndexes

Gets or sets an array of the DataGridItem indexes which are marked as selected.

Declaration
public virtual int[] SelectedIndexes { get; set; }
Property Value
Type Description
System.Int32[]

The selected indexes.

Remarks

The index can be used to get, for example, in the DataKeys collection to get the keys for the selected rows.

SelectionMode

Gets or sets the selection mode of the RowSelectorColumn.

Declaration
public virtual ListSelectionMode SelectionMode { get; set; }
Property Value
Type Description
System.Web.UI.WebControls.ListSelectionMode

The selection mode.

Remarks

Use the SelectionMode property to specify the mode behavior of the RowSelectorColumn. Setting this property to ListSelectionMode.Single indicates only a single item can be selected, while ListSelectionMode.Multiple specifies multiple items can be selected.

Methods

FindColumn(DataGrid)

Finds the first RowSelectorColumn in the given System.Web.UI.WebControls.DataGrid.

Declaration
public static RowSelectorColumn FindColumn(DataGrid grid)
Parameters
Type Name Description
System.Web.UI.WebControls.DataGrid grid

The System.Web.UI.WebControls.DataGrid to search.

Returns
Type Description
RowSelectorColumn

The RowSelectorColumn found, or null.

FindColumn(DataGrid, Int32)

Finds the first RowSelectorColumn in the given System.Web.UI.WebControls.DataGrid after or at the given column index.

Declaration
public static RowSelectorColumn FindColumn(DataGrid grid, int startIndex)
Parameters
Type Name Description
System.Web.UI.WebControls.DataGrid grid

The System.Web.UI.WebControls.DataGrid to search.

System.Int32 startIndex

The index of the column to start the search.

Returns
Type Description
RowSelectorColumn

The RowSelectorColumn found, or null.

InitializeCell(TableCell, Int32, ListItemType)

This member overrides System.Web.UI.WebControls.DataGridColumn.InitializeCell(System.Web.UI.WebControls.TableCell,System.Int32,System.Web.UI.WebControls.ListItemType).

Declaration
public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType)
Parameters
Type Name Description
System.Web.UI.WebControls.TableCell cell

A System.Web.UI.WebControls.TableCell that represents the cell to reset.

System.Int32 columnIndex

The column number where the cell is located.

System.Web.UI.WebControls.ListItemType itemType

One of the System.Web.UI.WebControls.ListItemType values.

OnSelectionChanged(EventArgs)

Raises the SelectionChanged event.

Declaration
protected virtual void OnSelectionChanged(EventArgs e)
Parameters
Type Name Description
System.EventArgs e

The System.EventArgs instance containing the event data.

RegisterForSelectAll(RowSelectorColumn.ParticipantCheckBox)

Registers the given checkbox as being bound to the SelectAll checkbox.

Declaration
protected virtual void RegisterForSelectAll(RowSelectorColumn.ParticipantCheckBox selector)
Parameters
Type Name Description
RowSelectorColumn.ParticipantCheckBox selector

The checkbox being bound.

RegisterSelectAllScript()

Emits the script library neccessary for the SelectAll behavior.

Declaration
protected virtual void RegisterSelectAllScript()

SetIndexValue(HtmlInputRadioButton)

Sets the value of the given selector to the row index.

Declaration
protected virtual void SetIndexValue(HtmlInputRadioButton radioSelector)
Parameters
Type Name Description
System.Web.UI.HtmlControls.HtmlInputRadioButton radioSelector

The radio selector.

Events

SelectionChanged

The event that is raised when the selection has changed.

Declaration
public event EventHandler SelectionChanged
Event Type
Type Description
System.EventHandler