Show / Hide Table of Contents

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
System.Web.UI.WebControls.DataGridColumn
RowSelectorColumn
Implements
System.Web.UI.IStateManager
Inherited Members
System.Web.UI.WebControls.DataGridColumn.Initialize()
System.Web.UI.WebControls.DataGridColumn.LoadViewState(System.Object)
System.Web.UI.WebControls.DataGridColumn.TrackViewState()
System.Web.UI.WebControls.DataGridColumn.OnColumnChanged()
System.Web.UI.WebControls.DataGridColumn.SaveViewState()
System.Web.UI.WebControls.DataGridColumn.ToString()
System.Web.UI.WebControls.DataGridColumn.System.Web.UI.IStateManager.LoadViewState(System.Object)
System.Web.UI.WebControls.DataGridColumn.System.Web.UI.IStateManager.TrackViewState()
System.Web.UI.WebControls.DataGridColumn.System.Web.UI.IStateManager.SaveViewState()
System.Web.UI.WebControls.DataGridColumn.DesignMode
System.Web.UI.WebControls.DataGridColumn.FooterStyle
System.Web.UI.WebControls.DataGridColumn.FooterText
System.Web.UI.WebControls.DataGridColumn.HeaderImageUrl
System.Web.UI.WebControls.DataGridColumn.HeaderStyle
System.Web.UI.WebControls.DataGridColumn.HeaderText
System.Web.UI.WebControls.DataGridColumn.ItemStyle
System.Web.UI.WebControls.DataGridColumn.Owner
System.Web.UI.WebControls.DataGridColumn.SortExpression
System.Web.UI.WebControls.DataGridColumn.ViewState
System.Web.UI.WebControls.DataGridColumn.Visible
System.Web.UI.WebControls.DataGridColumn.IsTrackingViewState
System.Web.UI.WebControls.DataGridColumn.System.Web.UI.IStateManager.IsTrackingViewState
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: MetaBuilders.WebControls
Assembly: SurveyProject.WebApplication.dll
Syntax
public class RowSelectorColumn : DataGridColumn, IStateManager
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
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

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
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
[Browsable(false)]
public virtual int[] SelectedIndexes { get; set; }
Property Value
Type Description
System.Int32[]
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
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
System.Int32 columnIndex
System.Web.UI.WebControls.ListItemType itemType
Overrides
System.Web.UI.WebControls.DataGridColumn.InitializeCell(System.Web.UI.WebControls.TableCell, System.Int32, System.Web.UI.WebControls.ListItemType)

OnSelectionChanged(EventArgs)

Raises the SelectionChanged event.

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

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

Events

SelectionChanged

The event that is raised when the selection has changed.

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

Implements

System.Web.UI.IStateManager
In This Article
Back to top Generated by DocFX