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

Filter template column that is bound in item databound event

3 Answers 252 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 18 Apr 2012, 06:39 PM
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>


3 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 18 Apr 2012, 07:23 PM
doesn't the filter work off the UniqueName, not the HeaderText?
0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Apr 2012, 07:52 PM
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
0
bharath
Top achievements
Rank 1
answered on 17 Apr 2015, 08:42 PM

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

 

Tags
Grid
Asked by
Justin
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Jayesh Goyani
Top achievements
Rank 2
bharath
Top achievements
Rank 1
Share this question
or