How to Customize a Data Grid

104 21
    • 1). Create a table style for the DataGrid. The "DataGridTableStyle" creates an object used to set a customized layout for the DataGrid. The following code creates a new style:

      Dim ts As New DataGridTableStyle()

    • 2). Create a new DataGrid column. Each column for your DataGrid is added to the table style. In this example, a one-column DataGrid is created for your page. The following code creates a column for the grid:

      Dim col As New DataGridTextBoxColumn()

      col.MappingName = "Name"

      col.HeaderText = "Customer Name"

      col.Width = 50

      The code above maps to the data named "Name" and sets up "Customer Name" at the top of the column. The width for the column is set for 50 pixels.

    • 3). Add the customized column to the table style object. The following code adds your customized column to the style:

      ts.GridColumnStyles.Add(col)

    • 4). Add the customized style to your DataGrid. This is the final step before the browser renders the DataGrid and sets up the style. The following code sets the style:

      Me.datagrid.TableStyles.Add(ts)

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.