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

Create Template Filter in code Behind

1 Answer 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Naografix
Top achievements
Rank 1
Naografix asked on 26 Jan 2015, 10:17 AM
Hey !

I want to create a filter Template in Code Behind, but it's hard for me, can you help me ?

I would like to be able to filter the names of technicians with a combobox !

This is my code :

protected void Page_Load(object sender, EventArgs e)
{
    GetGestionDoc();
}

{
    if (Session["NumStation"] != null)
    {
        int numStation = Convert.ToInt32(Session["NumStation"]);
        document = entities.V_RAPPORTSVALIDES.Where(p => p.ID_STATION == numStation).ToList();
 
        List<DocumentObject> newList = new List<DocumentObject>();
 
        foreach (var item in document)
        {
            DocumentObject o = new DocumentObject(item.TYPE_VISITE, item.TYPE_DOCUMENT, Convert.ToDateTime(item.DATE_DOCUMENT), Convert.ToInt16(item.ANNEE_RAPPORTANNUEL), item.NOM_TECHNICIEN);
            newList.Add(o);
        }
 
        RadCommentGrid.DataSource = newList;
        RadCommentGrid.DataBind();
 
        ChangeHeaderName();
    }
}

private void ChangeHeaderName()
{
    foreach (GridColumn column in RadCommentGrid.MasterTableView.AutoGeneratedColumns)
    {
        switch (column.OrderIndex)
        {
            case 2:
                column.HeaderText = "Date du document";
                break;
            case 3:
                column.HeaderText = "Type de document";
                break;
            case 4:
                column.HeaderText = "Nom du technicien";
                break;
            case 5:
                column.HeaderText = "Type de visite";
                break;
            case 6:
                column.HeaderText = "AnnĂ©e du rapport annuel";
                break;
        }
    }
 
    GridColumn columnDateDoc = RadCommentGrid.MasterTableView.AutoGeneratedColumns.Where(p => p.UniqueName == "DATE_DOCUMENT").FirstOrDefault();
    columnDateDoc.OrderIndex = 1;
 
    GridColumn columnTypeDoc = RadCommentGrid.MasterTableView.AutoGeneratedColumns.Where(p => p.UniqueName == "TYPE_DOCUMENT").FirstOrDefault();
    columnTypeDoc.OrderIndex = 2;
 
    GridColumn columnTechnicien = RadCommentGrid.MasterTableView.AutoGeneratedColumns.Where(p => p.UniqueName == "NOM_TECHNICIEN").FirstOrDefault();
    columnTechnicien.OrderIndex = 3;
 
    GridColumn columnVisite = RadCommentGrid.MasterTableView.AutoGeneratedColumns.Where(p => p.UniqueName == "TYPE_VISITE").FirstOrDefault();
    columnVisite.OrderIndex = 4;
 
    GridColumn columnAnnee = RadCommentGrid.MasterTableView.AutoGeneratedColumns.Where(p => p.UniqueName == "ANNEE_RAPPORTANNEE").FirstOrDefault();
    columnAnnee.OrderIndex = 5;
}


I see in your demo, you can create a filter with a radcombobox but its in XML :

<telerik:RadComboBox
     
    ID="RadComboBoxTitle"
     
    DataSourceID="SqlDataSource2"
     
    DataTextField="ContactTitle"
     
    DataValueField="ContactTitle"
     
    Height="200px"
     
    AppendDataBoundItems="true"
     
    SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("ContactTitle").CurrentFilterValue %>'
     
    runat="server"
     
    OnClientSelectedIndexChanged="TitleIndexChanged">
     
    <Items>
        <telerik:RadComboBoxItem Text="All" />
    </Items>
     
</telerik:RadComboBox>

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 29 Jan 2015, 08:58 AM
Hi Naografix,

I'm sending a sample RadGrid web site to demonstrate how you can add the filtering combo programmatically. Please run the attached application and let me know if it helps you.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Naografix
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or