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

Radgrid autofiltering

4 Answers 18 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vamsi
Top achievements
Rank 1
Vamsi asked on 25 Mar 2021, 07:32 PM

Hi, I'm new to telerik controls. I'm trying to implement auto filter option in the telerik radgrid

   <telerik:RadGrid ID="rgDashboard" ShowStatusBar="true" runat="server" AllowFilteringByColumn="true"
           AutoGenerateColumns="False" AllowSorting="true" OnNeedDataSource="RadGrid1_NeedDataSource"
           onsortcommand="rgDashboard_SortCommand" AllowPaging="true" PageSize="200">
           <GroupingSettings CaseSensitive="false" />
           <PagerStyle Mode="NumericPages" Position="TopAndBottom" ShowPagerText="false"> </PagerStyle>           
           <MasterTableView HeaderStyle-CssClass="goalGridHeader TableHeader" AllowFilteringByColumn="true">
           <Columns>               
                <telerik:GridBoundColumn DataField="Center" HeaderText="Center Name"                 
                 AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"
                            ShowFilterIcon="false" />
                <telerik:GridBoundColumn DataField="Instructor" HeaderText="Instructor Name" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"
                            ShowFilterIcon="false"   />
                <telerik:GridBoundColumn DataField="CenterID" HeaderText="Center ID" AllowFiltering="false"/>
                 <telerik:GridTemplateColumn  HeaderText="" AllowFiltering="false">
                    <ItemTemplate>
                      <asp:LinkButton ID="lnkEdit" Text="View" CssClass="btn btn-view btn-sm" OnClick="lnkEdit_OnClick" runat="server"  />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
            </MasterTableView>
        </telerik:RadGrid>

 

In code behind, I have filldata which binds the data to radgrid

 

  private void filldata()
        {
            DataSet ds = new DataSet();
            ds = gdh.GetCentersByFC(UserName, Admin, Email);
            try
            {
                if ((ds != null) && (ds.Tables.Count > 0) && (ds.Tables[0].Rows.Count > 0))
                {
                    lbldispBranch.Text = ds.Tables[0].Rows[0]["Branch"].ToString();
                   // lblLoggedInUser.Text = ds.Tables[0].Rows[0]["FCName"].ToString();
                }

                rgDashboard.DataSource = ds;
                rgDashboard.DataBind();
            }
            catch (Exception ex)
            {
                GeneralHelper.LogFile(ex);
            }
        }

  protected void rgDashboard_SortCommand(object sender, GridSortCommandEventArgs e)
        {
            filldata();
        }

        protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            filldata();
        }

I'm able to get the desired results, but getting below error after filter RadGrid1_NeedDataSource executes

Telerik.Web.UI.GridBindingException: You should not call DataBind in NeedDataSource event handler. DataBind would take place automatically right after NeedDataSource handler finishes execution.
   at Telerik.Web.UI.RadGrid.DataBind()

4 Answers, 1 is accepted

Sort by
0
Vamsi
Top achievements
Rank 1
answered on 25 Mar 2021, 09:24 PM
Does this needs to be done like this? because after I added this it started working without any errors.

 protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            //filldata();
            DataSet ds = new DataSet();
            ds = gdh.GetCentersByFC(UserName, Admin, Email);
            
            (sender as RadGrid).DataSource = ds; 
        }
0
Vessy
Telerik team
answered on 30 Mar 2021, 06:19 AM

Hi Vamsi,

There is no problem to make the data source settings into an external function like fillData(). You only have to make sure that the rgDashboard.DataBind() method is not called when it is triggered from the Grid's NeedDataSource event handler.

You can find more details on how to bind RadGrid properly in the following article:

https://www.telerik.com/support/kb/aspnet-ajax/grid/details/how-to-bind-radgrid-properly-on-server-side

Regards,
Vessy
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Vamsi
Top achievements
Rank 1
answered on 30 Mar 2021, 04:36 PM

Thank you Vessy.

I have one question on how to enable vertical scrolling on child radgrid. When I used  <ClientSettings> tag, it enabled scroll bar on Top level grid (telerik:RadGrid) but not on child grid (telerik:GridTableView)

 

 <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" ShowStatusBar="true" AutoGenerateColumns="False"
            PageSize="12" AllowSorting="True" AllowMultiRowSelection="False" AllowPaging="True"
            OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnNeedDataSource="RadGrid1_NeedDataSource"
            OnPreRender="RadGrid1_PreRender">
             <ClientSettings>
                    <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="true"></Scrolling>
                </ClientSettings>
            <PagerStyle Mode="NumericPages"></PagerStyle>
            <MasterTableView DataKeyNames="MonthNumber" AllowMultiColumnSorting="True" GroupsDefaultExpanded="false">
                <DetailTables>
                
                    <telerik:GridTableView DataKeyNames="CenterID" Name="Orders" Width="100%" AllowPaging="true" PageSize="50" GroupsDefaultExpanded="false">
                    <Columns>
                        
                        <telerik:GridBoundColumn SortExpression="CenterName" HeaderText="Center Name" HeaderButtonType="TextButton"
                        DataField="CenterName">

 </Columns>
                    </telerik:GridTableView>
                </DetailTables>
                <Columns>
                    <telerik:GridBoundColumn SortExpression="MonthName" HeaderText="MonthName" HeaderButtonType="TextButton"
                        DataField="MonthName">
                    </telerik:GridBoundColumn>

 </Columns>
            </MasterTableView>
        </telerik:RadGrid>

0
Vessy
Telerik team
answered on 31 Mar 2021, 06:30 PM

Hello Vamsi,

You can see how to add separate scrolling for the inner tables of a hierarchical RadGrid here:

https://www.telerik.com/support/code-library/separate-scrolls-for-inner-tables-in-hierarchical-grid

In addition, we would like to kindly ask you to open separate threads for each issue that your are facing. Thank you in advance for your understanding.

Regards,
Vessy
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
Vamsi
Top achievements
Rank 1
Answers by
Vamsi
Top achievements
Rank 1
Vessy
Telerik team
Share this question
or