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

RadGrid set filter width and autopostback programmatically

3 Answers 193 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sigifredo
Top achievements
Rank 1
Sigifredo asked on 08 Oct 2012, 04:31 PM
Hi 

I have a RadGrid on my aspx page with no columns defined as follows:

    <telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowSelection="True" Skin="Metro"
        GroupingEnabled="true" ShowGroupPanel="True" GridLines="None" EnableLinqExpressions="false">
        <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true">
            <Excel Format="ExcelML" />
        </ExportSettings>
        <MasterTableView TableLayout="Fixed" AutoGenerateColumns="true" Width="100%" CommandItemDisplay="Top"
            AllowMultiColumnSorting="True" GroupLoadMode="Server" ShowGroupFooter="true"
            AllowSorting="True" AllowPaging="True" PageSize="20" ShowFooter="false" HeaderStyle-HorizontalAlign="left"
            FooterStyle-HorizontalAlign="Right" EnableHeaderContextMenu="true" EnableHeaderContextAggregatesMenu="true"
            AllowFilteringByColumn="True" HeaderStyle-BackColor="Black" HeaderStyle-ForeColor="White">
            <CommandItemSettings ShowExportToExcelButton="true" />
            <NoRecordsTemplate>
                <div class="NoRecordsTemplate">
                    No records to view</div>
            </NoRecordsTemplate>
        </MasterTableView>
        <ClientSettings AllowDragToGroup="true" EnableRowHoverStyle="true" AllowColumnsReorder="true"
            ReorderColumnsOnClient="true">
            <Selecting AllowRowSelect="True"></Selecting>
            <Resizing AllowResizeToFit="true" AllowColumnResize="True" EnableRealTimeResize="True">
            </Resizing>
        </ClientSettings>
        <GroupingSettings CaseSensitive="false" ShowUnGroupButton="True" RetainGroupFootersVisibility="true" />
        <PagerStyle Mode="NextPrevNumericAndAdvanced" />
    </telerik:RadGrid> 

On my code-behind page I populate the RadGrid using the GetDataTable function as follows:

    Public Function GetDataTable(ByVal query As String) As DataTable
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("SQLConn").ConnectionString
        Dim conn As SqlConnection = New SqlConnection(ConnString)
        Dim adapter As SqlDataAdapter = New SqlDataAdapter
        adapter.SelectCommand = New SqlCommand(query, conn)
        Dim table1 As New DataTable
        conn.Open()
        Try
            adapter.Fill(table1)
        Finally
            conn.Close()
        End Try
        Return table1
    End Function

What I am trying to do is hide the filter icon, set AutoPostBackOnFilter=True and set filter width to auto fit programmatically.

I was able to hide the filter icon by using the following:
    <style>
        .RadGrid .rgFilter
        {
            display: none;
        }
    </style>

However, I can't figure how to set AutoPostBackOnFilter=True and set filter width to auto fit programmatically.

How can I accomplish this?

Thanks,

Sigi Perez

 

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 08 Oct 2012, 05:15 PM
Hello,

Please try with below code snippet.

protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
        {
            if (e.Column.UniqueName == "YourdataFieldName")
            // OR
            //if (e.Column.HeaderText == "YourdataFieldName")
            {
                e.Column.AutoPostBackOnFilter = true;
                e.Column.FilterControlWidth = Unit.Pixel(100);
            }
        }


Thanks,
Jayesh Goyani
0
Sigifredo
Top achievements
Rank 1
answered on 08 Oct 2012, 06:10 PM
Hi Jayesh Goyani,

Thank you for your response. This will work fine if I know the field names. However, the reason I setup the RadGrid on the aspx page without columns is because I user the grid to populate different queries dynamically. For instance one user may run the query "select * from customers" while other may run "select * from products". in other words, I don't know the field names because that depends on the query selected.

I hope I didn't confuse you...

Thanks,

Sigi Perez 
0
Sigifredo
Top achievements
Rank 1
answered on 08 Oct 2012, 06:15 PM
Never mind Jayesh Goyani,

I didn't realize you actually provided the answer in your code snippet.

Thanks for your help on this.

Sigi Perez
Tags
Grid
Asked by
Sigifredo
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Sigifredo
Top achievements
Rank 1
Share this question
or