This topic has not yet been rated - Rate this topic

BoundColumn Class

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

System.Object
  System.Web.UI.WebControls.DataGridColumn
    System.Web.UI.WebControls.BoundColumn

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
public class BoundColumn : DataGridColumn

The BoundColumn type exposes the following members.

  Name Description
Public method BoundColumn Initializes a new instance of the BoundColumn class.
Top
  Name Description
Public property DataField Gets or sets the field name from the data source to bind to the BoundColumn.
Public property DataFormatString Gets or sets the string that specifies the display format for items in the column.
Protected property DesignMode Gets a value that indicates whether the column is in design mode. (Inherited from DataGridColumn.)
Public property FooterStyle Gets the style properties for the footer section of the column. (Inherited from DataGridColumn.)
Public property FooterText Gets or sets the text displayed in the footer section of the column. (Inherited from DataGridColumn.)
Public property HeaderImageUrl Gets or sets the location of an image to display in the header section of the column. (Inherited from DataGridColumn.)
Public property HeaderStyle Gets the style properties for the header section of the column. (Inherited from DataGridColumn.)
Public property HeaderText Gets or sets the text displayed in the header section of the column. (Inherited from DataGridColumn.)
Protected property IsTrackingViewState Gets a value that determines whether the DataGridColumn object is marked to save its state. (Inherited from DataGridColumn.)
Public property ItemStyle Gets the style properties for the item cells of the column. (Inherited from DataGridColumn.)
Protected property Owner Gets the DataGrid control that the column is a member of. (Inherited from DataGridColumn.)
Public property ReadOnly Gets or sets a value that indicates whether the items in the BoundColumn can be edited.
Public property SortExpression Gets or sets the name of the field or expression to pass to the OnSortCommand method when a column is selected for sorting. (Inherited from DataGridColumn.)
Protected property ViewState Gets the System.Web.UI.StateBag object that allows a column derived from the DataGridColumn class to store its properties. (Inherited from DataGridColumn.)
Public property Visible Gets or sets a value that indicates whether the column is visible in the DataGrid control. (Inherited from DataGridColumn.)
Top
  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Protected method FormatDataValue Converts the specified value to the format indicated by the DataFormatString property.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Initialize Resets the BoundColumn to its initial state. (Overrides DataGridColumn.Initialize().)
Public method InitializeCell Resets the specified cell in the BoundColumn to its initial state. (Overrides DataGridColumn.InitializeCell(TableCell, Int32, ListItemType).)
Protected method LoadViewState Loads the state of the DataGridColumn object. (Inherited from DataGridColumn.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method OnColumnChanged Calls the DataGridDesigner.OnColumnsChanged method. (Inherited from DataGridColumn.)
Protected method SaveViewState Saves the current state of the DataGridColumn object. (Inherited from DataGridColumn.)
Public method ToString Returns the string representation of the column. (Inherited from DataGridColumn.)
Protected method TrackViewState Causes tracking of view-state changes to the server control so they can be stored in the server control's System.Web.UI.StateBag object. (Inherited from DataGridColumn.)
Top
  Name Description
Public field Static member thisExpr Represents the string "!". This field is read-only.
Top
  Name Description
Explicit interface implemetation Private property IStateManager.IsTrackingViewState Infrastructure. Gets a value that indicates whether the column is tracking view state changes. (Inherited from DataGridColumn.)
Explicit interface implemetation Private method IStateManager.LoadViewState Infrastructure. Loads previously saved state. (Inherited from DataGridColumn.)
Explicit interface implemetation Private method IStateManager.SaveViewState Infrastructure. Returns an object containing state changes. (Inherited from DataGridColumn.)
Explicit interface implemetation Private method IStateManager.TrackViewState Infrastructure. Starts tracking state changes. (Inherited from DataGridColumn.)
Top

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 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 note 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.

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>



.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ