title: Format BoundField Data Types Dynamically
body: <p>I'm using a CheckBoxList to define which columns are displayed in a GridView. I populate the CheckBoxList using a query like</p>
  
  <pre><code>select column_name, data_type from information_schema.columns
      where table_name = 'myTable'
  </code></pre>
  
  <p>After the user has chosen the columns (with various Data Types in them) they wish to display, they press a button and the following snippet of VB code generates the GridView.</p>
  
  <pre><code>For Each item As ListItem In chooseColsList.Items
      If item.Selected Then
          Dim bf As New BoundField()
          'PRODUCES BUGGY RESULTS BECAUSE APPLIED TO ALL BoundFields
          bf.DataFormatString = "{0:dd-MMM-yyyy}"
          bf.ApplyFormatInEditMode = True
          bf.DataField = item.Value
          bf.HeaderText = item.Value
          bf.SortExpression = item.Value
          statusReportGrid.Columns.Add(bf)
      End If
  Next
  </code></pre>
  
  <p>What I want to do is to apply the DataFormatString ONLY to the columns with a 'date' Data Type in them. However, I have found no way of programmatically determining the Type of the data in the column being bound, no any way of passing this info to the Control. This information exists in the information_schema, as shown in my query, but I don't know how to extract that out and use it to <strong>dynamically</strong> setup my BoundFields. It is important to note that I'm using an <strong>SqlDataSource</strong>.</p>
  
  <p>I've experimented with just about every possible solution I can think of and end up here.</p>
  
  <p>Thanks in advance for your help, it is VERY appreciated :)</p>