Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 4th, 2012  |  syntax: None  |  size: 1.15 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Format BoundField Data Types Dynamically
  2. select column_name, data_type from information_schema.columns
  3.     where table_name = 'myTable'
  4.        
  5. For Each item As ListItem In chooseColsList.Items
  6.     If item.Selected Then
  7.         Dim bf As New BoundField()
  8.         'PRODUCES BUGGY RESULTS BECAUSE APPLIED TO ALL BoundFields
  9.         bf.DataFormatString = "{0:dd-MMM-yyyy}"
  10.         bf.ApplyFormatInEditMode = True
  11.         bf.DataField = item.Value
  12.         bf.HeaderText = item.Value
  13.         bf.SortExpression = item.Value
  14.         statusReportGrid.Columns.Add(bf)
  15.     End If
  16. Next
  17.        
  18. <asp:checkboxlist id="list" runat="server"  
  19. DataTextField="column_name" DataValueField="data_type" DataSourceID="YourDSID" />
  20.        
  21. For Each item As ListItem In chooseColsList.Items
  22.     If item.Selected Then
  23.         Dim bf As New BoundField()
  24.  
  25.         If StrComp(item.Value,"date") = 0 Then 'Or however datetime is returned
  26.             bf.DataFormatString = "{0:dd-MMM-yyyy}"
  27.             bf.ApplyFormatInEditMode = True
  28.         End If
  29.         bf.DataField = item.Text
  30.         bf.HeaderText = item.Text
  31.         bf.SortExpression = item.Text
  32.         statusReportGrid.Columns.Add(bf)
  33.     End If
  34. Next