Edit

Share via


BoundColumn Class

Definition

A column type for the DataGrid control that is bound to a field in a data source.

public ref class BoundColumn : System::Web::UI::WebControls::DataGridColumn
public class BoundColumn : System.Web.UI.WebControls.DataGridColumn
type BoundColumn = class
    inherit DataGridColumn
Public Class BoundColumn
Inherits DataGridColumn
Inheritance
BoundColumn

Examples

The following example demonstrates how to use a BoundColumn column type in the DataGrid control to display the fields in a data source.

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
   <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)));
         dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));
 
         for (int i = 0; i < 9; i++) 
         {
            dr = dt.NewRow();
 
            dr[0] = i;
            dr[1] = "Item " + i.ToString();
            dr[2] = 1.23 * (i + 1);
 
            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();
         }
      }
 
   </script>
 
<head runat="server">
    <title>BoundColumn Example</title>
</head>
<body>
 
   <form id="form1" runat="server">
 
      <h3>BoundColumn Example</h3>
 
      <b>Product List</b>
 
      <asp:DataGrid id="ItemsGrid"
           BorderColor="black"
           BorderWidth="1"
           CellPadding="3"
           AutoGenerateColumns="false"
           runat="server">

         <HeaderStyle BackColor="#00aaaa">
         </HeaderStyle>

         <Columns>

            <asp:BoundColumn
                 HeaderText="Number" 
                 DataField="IntegerValue">
            </asp:BoundColumn>

            <asp:BoundColumn
                 HeaderText="Description" 
                 DataField="StringValue">
            </asp:BoundColumn>

            <asp:BoundColumn
                 HeaderText="Price" 
                 DataField="CurrencyValue" 
                 DataFormatString="{0:c}">
            </asp:BoundColumn>

         </Columns>
 
      </asp:DataGrid>
 
   </form>
 
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
   <script language="VB" runat="server">
    Function CreateDataSource() As ICollection
        Dim dt As New DataTable()
        Dim dr As DataRow
        
        dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
        dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
        dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
        
        Dim i As Integer
        For i = 0 To 8
            dr = dt.NewRow()
            
            dr(0) = i
            dr(1) = "Item " + i.ToString()
            dr(2) = 1.23 *(i + 1)
            
            dt.Rows.Add(dr)
        Next i
        
        Dim dv As New DataView(dt)
        Return dv
    End Function 'CreateDataSource


    Sub Page_Load(sender As Object, e As EventArgs)
        
        If Not IsPostBack Then
            ' Load this data only once.
            ItemsGrid.DataSource = CreateDataSource()
            ItemsGrid.DataBind()
        End If
    End Sub 'Page_Load
   </script>
<head runat="server">
    <title>BoundColumn Example</title>
</head>
<body>
 
   <form id="form1" runat="server">
 
      <h3>BoundColumn Example</h3>
 
      <b>Product List</b>
 
      <asp:DataGrid id="ItemsGrid"
           BorderColor="black"
           BorderWidth="1"
           CellPadding="3"
           AutoGenerateColumns="false"
           runat="server">

         <HeaderStyle BackColor="#00aaaa">
         </HeaderStyle>

         <Columns>

            <asp:BoundColumn
                 HeaderText="Number" 
                 DataField="IntegerValue">
            </asp:BoundColumn>

            <asp:BoundColumn
                 HeaderText="Description" 
                 DataField="StringValue">
            </asp:BoundColumn>

            <asp:BoundColumn
                 HeaderText="Price" 
                 DataField="CurrencyValue" 
                 DataFormatString="{0:c}">
            </asp:BoundColumn>

         </Columns>
 
      </asp:DataGrid>
 
   </form>
 
</body>
</html>

Remarks

Use the BoundColumn column type in a DataGrid control to display the contents of a field in the data source. The values are listed in a single column. The field is linked to the BoundColumn, so any updates in the data source will reflect in the corresponding cells of the DataGrid control.

Note

This column type is the default for the DataGrid control.

To control appearance of this column, use the style properties of the DataGrid control.

Caution

Text is not HTML encoded before it is displayed in the BoundColumn. This makes it possible to embed script within HTML tags in the text. If the values for this column come from user input, be sure to validate the values to reduce security vulnerabilities.

Constructors

BoundColumn()

Initializes a new instance of the BoundColumn class.

Fields

thisExpr

Represents the string "!". This field is read-only.

Properties

DataField

Gets or sets the field name from the data source to bind to the BoundColumn.

DataFormatString

Gets or sets the string that specifies the display format for items in the column.

DesignMode

Gets a value that indicates whether the column is in design mode.

(Inherited from DataGridColumn)
FooterStyle

Gets the style properties for the footer section of the column.

(Inherited from DataGridColumn)
FooterText

Gets or sets the text displayed in the footer section of the column.

(Inherited from DataGridColumn)
HeaderImageUrl

Gets or sets the location of an image to display in the header section of the column.

(Inherited from DataGridColumn)
HeaderStyle

Gets the style properties for the header section of the column.

(Inherited from DataGridColumn)
HeaderText

Gets or sets the text displayed in the header section of the column.

(Inherited from DataGridColumn)
IsTrackingViewState

Gets a value that determines whether the DataGridColumn object is marked to save its state.

(Inherited from DataGridColumn)
ItemStyle

Gets the style properties for the item cells of the column.

(Inherited from DataGridColumn)
Owner

Gets the DataGrid control that the column is a member of.

(Inherited from DataGridColumn)
ReadOnly

Gets or sets a value that indicates whether the items in the BoundColumn can be edited.

SortExpression

Gets or sets the name of the field or expression to pass to the OnSortCommand(DataGridSortCommandEventArgs) method when a column is selected for sorting.

(Inherited from DataGridColumn)
ViewState

Gets the StateBag object that allows a column derived from the DataGridColumn class to store its properties.

(Inherited from DataGridColumn)
Visible

Gets or sets a value that indicates whether the column is visible in the DataGrid control.

(Inherited from DataGridColumn)

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
FormatDataValue(Object)

Converts the specified value to the format indicated by the DataFormatString property.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
Initialize()

Resets the BoundColumn to its initial state.

InitializeCell(TableCell, Int32, ListItemType)

Resets the specified cell in the BoundColumn to its initial state.

LoadViewState(Object)

Loads the state of the DataGridColumn object.

(Inherited from DataGridColumn)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnColumnChanged()

Calls the OnColumnsChanged() method.

(Inherited from DataGridColumn)
SaveViewState()

Saves the current state of the DataGridColumn object.

(Inherited from DataGridColumn)
ToString()

Returns the string representation of the column.

(Inherited from DataGridColumn)
TrackViewState()

Causes tracking of view-state changes to the server control so they can be stored in the server control's StateBag object.

(Inherited from DataGridColumn)

Explicit Interface Implementations

IStateManager.IsTrackingViewState

Gets a value that indicates whether the column is tracking view state changes.

(Inherited from DataGridColumn)
IStateManager.LoadViewState(Object)

Loads previously saved state.

(Inherited from DataGridColumn)
IStateManager.SaveViewState()

Returns an object containing state changes.

(Inherited from DataGridColumn)
IStateManager.TrackViewState()

Starts tracking state changes.

(Inherited from DataGridColumn)

Applies to

See also