This is a migrated thread and some comments may be shown as answers.

Change data type of dynamic columns

1 Answer 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kush
Top achievements
Rank 1
Kush asked on 25 Sep 2013, 04:32 AM
Public Function GetDataTable(ByVal query As String) As DataTable
    Dim ConnString As [String] = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
    Dim adapter As New SqlDataAdapter()
    Dim myDataTable As New DataTable()
    Using conn As New SqlConnection(ConnString)
        adapter.SelectCommand = New SqlCommand(query, conn)
        adapter.Fill(myDataTable)
    End Using
    Return myDataTable
End Function

RadGrid1.DataSource = GetDataTable(q.ToString)
RadGrid1.DataBind()

Now I have created columns dynamically. I want to set the first column as a datetype column.

Protected Sub RadGrid1_PreRender(sender As Object, e As System.EventArgs) Handles RadGrid1.PreRender
 
    Dim expression As GridSortExpression = New GridSortExpression()
    expression.FieldName = "Column1"
 
    expression.SortOrder = GridSortOrder.Descending
    RadGrid1.MasterTableView.SortExpressions.AddSortExpression(expression)
 
    Dim dt As GridBoundColumn = RadGrid1.MasterTableView.GetColumnSafe("Column1")
 
    If dt IsNot Nothing Then
        'dt.DataType = TypeOf(DateTime.Now.ToString) << -- NOT WORKING
    End If
 
    RadGrid1.MasterTableView.Rebind()
End Sub

Is there anyway to set Datatype of a column from code-behind.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 25 Sep 2013, 05:01 AM
Hi Kush,

Please try the following code snippet.

VB:
Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs)
   RadGrid1.MasterTableView.GetColumnSafe("Column1").DataType = GetType(DateTime)
End Sub

Thanks,
Princy
Tags
Grid
Asked by
Kush
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or