Filter template column that is bound in item databound event

4 posts, 0 answers
  1. Justin
    Justin avatar
    5 posts
    Member since:
    Oct 2011

    Posted 18 Apr 2012 Link to this post

    Hello,

    I have a radgrid with a template column which has a label that has its text set during the itemDatabound Event. How can I filter on this column?


    protected void rgCompany_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if(e.Item is GridDataItem)
            {
                Label contactName = e.Item.FindControl("Label1") as Label;
                MainContact mc =
                    CharityChallenge_DAO.GetMainContactForCompany((e.Item.DataItem as Company).CompanyIdentifier);
                if(mc != null)
                    contactName.Text = mc.FirstName + " " + mc.LastName;
            }
        }
     
        protected void rgCompany_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            List<Company> companyList = CharityChallenge_DAO.GetCompanies();
            rgCompany.DataSource = companyList ?? new List<Company>();
     
        }


          
         <telerik:RadGrid ID="rgCompany" runat="server" AutoGenerateColumns="False"
                CellSpacing="0" GridLines="None"
        oninsertcommand="rgCompany_InsertCommand" onitemcommand="rgCompany_ItemCommand"
        onneeddatasource="rgCompany_NeedDataSource"
        onupdatecommand="rgCompany_UpdateCommand" EnableLinqExpressions="False"
                AllowFilteringByColumn="True" AllowSorting="True" Height="700px"
                onitemdatabound="rgCompany_ItemDataBound"
                >
    <ClientSettings>
    <Selecting CellSelectionMode="None"></Selecting>
        <scrolling allowscroll="True" usestaticheaders="True" />
    </ClientSettings>
     
    <MasterTableView DataKeyNames="CompanyIdentifier" CommandItemDisplay="Top" ShowHeadersWhenNoRecords="true"  AllowFilteringByColumn="True"
                    NoMasterRecordsText="No Companies have been added"
                    InsertItemDisplay="Bottom" GridLines="None" >
      <NoRecordsTemplate><div style="text-align: center;"><span style="color: Red;">No Companies have been added</span></div></NoRecordsTemplate>
                    <CommandItemSettings AddNewRecordText="Add a Company" />
                    <CommandItemTemplate>
                        <span class="radGridTitleSpan">Companies</span>
                        <div style="text-align: right;">
                             <asp:LinkButton ID="btnInsert" runat="server"
                CommandName="InitInsert" class="button secondaryAction">Add New Company</asp:LinkButton>
                    
                        </div>
                    </CommandItemTemplate>
     
    <CommandItemSettings AddNewRecordText="Add a Company" ExportToPdfText="Export to PDF"></CommandItemSettings>
     
    <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
    <HeaderStyle Width="20px"></HeaderStyle>
    </RowIndicatorColumn>
     
    <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
    <HeaderStyle Width="20px"></HeaderStyle>
    </ExpandCollapseColumn>
     
        <Columns>
            <telerik:GridBoundColumn FilterControlAltText="Filter column column" DataField="CompanyIdentifier" Visible="False"
                UniqueName="CompanyIdentifier">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter column1 column"  DataField="CompanyName" HeaderText="Company Name" FilterListOptions="VaryByDataType"
                UniqueName="CompanyName">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn column"  FilterListOptions="VaryByDataTypeAllowCustom"
                HeaderText="Company Contact" UniqueName="CompanyContact" AllowFiltering="True">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter column3 column" DataField="LastUpdatedUserIdentifier" HeaderText="Last Updated User Id"
                UniqueName="LastUpdatedUserIdentifier">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter column4 column" DataField="LastUpdatedTimestamp" HeaderText="Last Updated Time"
                UniqueName="LastUpdatedTimestamp">
            </telerik:GridBoundColumn>
            <telerik:GridEditCommandColumn FilterControlAltText="Filter EditCommandColumn column">
            </telerik:GridEditCommandColumn>
        </Columns>
     
    <EditFormSettings EditFormType="WebUserControl"
            UserControlName="CompanyWebCntrl.ascx">
    <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
    </EditFormSettings>
    </MasterTableView>
     
    <FilterMenu EnableImageSprites="False">
    <WebServiceSettings>
    <ODataSettings InitialContainerName=""></ODataSettings>
    </WebServiceSettings>
    </FilterMenu>
     
    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
    <WebServiceSettings>
    <ODataSettings InitialContainerName=""></ODataSettings>
    </WebServiceSettings>
    </HeaderContextMenu>
            </telerik:RadGrid>


  2. Elliott
    Elliott avatar
    391 posts
    Member since:
    May 2010

    Posted 18 Apr 2012 Link to this post

    doesn't the filter work off the UniqueName, not the HeaderText?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 18 Apr 2012 Link to this post

    Hello Justin,

    we are not able to set filter in itemdatabound because after applying the filter in to grid we must have to rebind or re-assign the datasource to radgrid.

    please check below link for how to apply filter on initial load.
    http://www.telerik.com/help/aspnet-ajax/grid-applying-default-filter-on-initial-load.html
    http://www.telerik.com/help/aspnet/grid/grdapplyingdefaultfilteroninitialload.html

    Thanks,
    Jayesh Goyani
  5. bharath
    bharath avatar
    23 posts
    Member since:
    Jun 2011

    Posted 17 Apr 2015 in reply to Jayesh Goyani Link to this post

    Hi Jayesh Goyani

       i  created radgrid with boundtempletecolumns (TextBox,Combobox..)

     dataSourse having 100 rows. while binding it is very slow. how can i improve the performance.

    With Regards

    Bharath

     

Back to Top