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

[Solved] Filter RadComboBox Column in RadGrid with ID instead of Name

0 Answers 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ABC
Top achievements
Rank 1
ABC asked on 28 Apr 2013, 08:14 AM
I have the following Column in my RadGrid,

<Telerik:DDLGridColumn UniqueName="ProductType"
                    Query="select Name AS ProductType, ID AS ProductTypeID From ProductTypes WHERE RetailerID={1}"
                    GetRetailerIDFromSession="True"
                    DataField="ProductType" DataValueField="ProductTypeID"
                    HeaderText="ProductType" SortExpression="ProductType">
                    <ItemTemplate>
                        <%# Eval("ProductType")%>
                    </ItemTemplate>
</Telerik:DDLGridColumn>

This is the code,

    
public class DDLGridColumn: GridTemplateColumn
    {
        protected override void SetupFilterControls(System.Web.UI.WebControls.TableCell cell)
        {
            RadComboBox rcBox = new RadComboBox();
            rcBox.ID = this.UniqueName + "_rcbox";
            rcBox.AutoPostBack = true;
            rcBox.DataTextField = this.DataField;
            rcBox.DataValueField = DataValueField ?? this.DataField;
            rcBox.SelectedIndexChanged += rcBox_SelectedIndexChanged;
            rcBox.Width = FilterControlWidth;
            string query = query = string.Format(this.Query, this.DataField);
            DataTable table = DBLayer.GetDataTable(query, CommandType.Text);
            DataRow row = table.NewRow();
            table.Rows.InsertAt(row, 0);
            rcBox.DataSource = table;
            cell.Controls.Add(rcBox);
        }
        private void rcBox_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            ((GridFilteringItem)(((RadComboBox)sender).Parent.Parent)).FireCommandEvent("Filter", new Pair());
        }
        protected override void SetCurrentFilterValueToControl(TableCell cell)
        {
            if (!(this.CurrentFilterValue == ""))
            {
                ((RadComboBox)cell.Controls[0]).Items.FindItemByValue(this.CurrentFilterValue).Selected = true;
            }
        }
        protected override string GetCurrentFilterValueFromControl(TableCell cell)
        {
            string currentValue = ((RadComboBox)cell.Controls[0]).SelectedItem.Value;
            this.CurrentFilterFunction = (currentValue != "") ? GridKnownFunction.EqualTo : GridKnownFunction.NoFilter;
            return currentValue;
        }
    }

I want the RadComboBox to filter with ID, but on UI it should show name. Is it possible

No answers yet. Maybe you can help?

Tags
Grid
Asked by
ABC
Top achievements
Rank 1
Share this question
or