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

[Solved] RadGrid Programmatic Column Creation Filter Problem

1 Answer 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 01 Aug 2013, 09:03 AM
Hi All,

I am using RadGrid control and creating one grid column programmatically but the problem is that when I use filter of that column it gives me an error radgrid is neither a DataColumn nor a DataRelation for table. I can view that column but when I try to filter the records using the date filter then it produces an error.

Also, how can I set the index of that column as I want to set the position of that column as number three because before that I have two more columns edit and delete.

Any help would be greatly appreciated.

Thanks in advance.


<telerik:RadGrid ID="rgList" Width="100%" AllowFilteringByColumn="true" Skin="Metro"
        CssClass="table table-bordered" AutoGenerateDeleteColumn="false" AutoGenerateEditColumn="false"
        EnableEmbeddedBaseStylesheet="true" AllowSorting="True" AllowPaging="false" PageSize="10"
        ShowHeader="true" runat="server" AutoGenerateColumns="true" ShowStatusBar="true">
        <MasterTableView TableLayout="Auto" CommandItemDisplay="Top">
            <CommandItemSettings ShowRefreshButton="false" ShowAddNewRecordButton="false" ShowExportToCsvButton="true"
                ShowExportToExcelButton="true" />
        </MasterTableView>
        <GroupingSettings CaseSensitive="false" />
    </telerik:RadGrid>
 
 
 Protected Sub rgList_ColumnCreated(ByVal sender As Object, ByVal e As GridColumnCreatedEventArgs) Handles rgList.ColumnCreated
 
        If e.Column.UniqueName = "AutoGeneratedDeleteColumn" Then 'auto generated delete column id
            Dim gridButtonColumn As GridButtonColumn = e.Column
            gridButtonColumn.ConfirmText = Constants.DELETE_CONFIRM_MESSAGE
        ElseIf e.Column.UniqueName = Constants.EDIT Then
            TryCast(e.Column, GridBoundColumn).AllowFiltering = False
            TryCast(e.Column, GridBoundColumn).HeaderText = ""
        ElseIf e.Column.UniqueName = Constants.DELETE Then 'hiding Delete column from database
            e.Column.Visible = False
        ElseIf e.Column.UniqueName.Contains("_") Then
            Dim sColType As String = e.Column.UniqueName.Split("_")(1)
            If sColType = "GridDateTimeColumn" Then
                Dim _GridDateTimeColumn As New GridDateTimeColumn
                _GridDateTimeColumn.DataField = e.Column.UniqueName
                _GridDateTimeColumn.HeaderText = "Callback Date"
                _GridDateTimeColumn.EnableRangeFiltering = True
                _GridDateTimeColumn.AutoPostBackOnFilter = True
                rgList.MasterTableView.Columns.Add(_GridDateTimeColumn)
            End If
        Else
            e.Column.AutoPostBackOnFilter = True
            e.Column.CurrentFilterFunction = GridKnownFunction.Contains 'setting filter for all other columns
        End If
 
    End Sub
 

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 06 Aug 2013, 06:49 AM
Hi,

If you want to have programmatically defined columns you should use Page_Init and Page_Load events. In your case since the Grid is defined declaratively you should use Page_Load event as described in this topic.

Autogenerated columns should be used when you do not want any customization. ColumnCreated event is used to change some visual properties but not define any new columns.

Regards,
Andrey
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Muhammad
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or