Not logged in - Login

Basic ASPxGridView Grid Data Display

Add the DevExpress grid to the web page. Use the designer to add columns to the grid. Be sure to specify the 'FieldName' property of each column. This value determines what field from the data source is displayed in the column. The following illustrates a sample of how the grid source will look in the HTML:

<dxwgv:ASPxGridView ID="grdTest" runat="server" AutoGenerateColumns="False">
   <Columns>
      <dxwgv:GridViewDataTextColumn Caption="lRowID" FieldName="lRowID" Name="lRowID" VisibleIndex="0" ReadOnly="True">
      </dxwgv:GridViewDataTextColumn>

      <dxwgv:GridViewDataTextColumn Caption="sText" FieldName="sText" Name="sText" VisibleIndex="1">
      </dxwgv:GridViewDataTextColumn>

      <dxwgv:GridViewDataTextColumn Caption="lNumber" FieldName="lNumber" Name="lNumber" VisibleIndex="2">
      </dxwgv:GridViewDataTextColumn>

      <dxwgv:GridViewDataDateColumn Caption="dtDate" FieldName="dtDate" Name="dtDate" VisibleIndex="3">
         <PropertiesDateEdit DisplayFormatString="M/d/yyyy">
         </PropertiesDateEdit>
      </dxwgv:GridViewDataDateColumn>

      <dxwgv:GridViewDataCheckColumn Caption="bFlag" FieldName="bFlag" Name="bFlag" VisibleIndex="4">
      </dxwgv:GridViewDataCheckColumn>

      <dxwgv:GridViewDataComboBoxColumn Caption="lNumberCbo" FieldName="lNumber" Name="lNumberCbo" VisibleIndex="5">
         <PropertiesComboBox ValueType="System.String">
         <Items>
         <dxe:ListEditItem Text="Zero" Value="0" />
         <dxe:ListEditItem Text="One" Value="1" />
         <dxe:ListEditItem Text="Two" Value="2" />
         <dxe:ListEditItem Text="Three" Value="3" />
         <dxe:ListEditItem Text="Four" Value="4" />
         </Items>
         </PropertiesComboBox>
      </dxwgv:GridViewDataComboBoxColumn>
   </Columns>

   <SettingsPager PageSize="10">
   </SettingsPager>
</dxwgv:ASPxGridView>

In the Load event of the form, retrieve the data and bind it to the grid. It will look something like the following:

// get the sample data
DataTable tbl = null;
tbl = SampleData.GetSampleData1();

// bind the data to the grid.
this.grdTest.DataSource = tbl;
if (!this.IsPostback && !this.IsCallback)
{
   this.grdTest.DataBind();
}

This must be done every time the Load event is fired on the form, even on postbacks.