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

[Solved] Ajax Binding and ItemTemplate

1 Answer 139 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
GD
Top achievements
Rank 1
GD asked on 11 Mar 2010, 12:47 PM


                            <telerik:RadComboBox ID="radCombo5"   
                                                 runat="server"   
                                                 Width="250px"   
                                                 Height="150px" 
                                                 DropDownWidth="298px" 
                                                 EnableLoadOnDemand="true"   
                                                 EnableVirtualScrolling="true" 
                                                 MarkFirstMatch="false" 
                                                 HighlightTemplatedItems="true" 
                                                 EmptyMessage="Digitare il comune da ricercare" 
                                                 OnClientItemsRequesting="radCombo5_OnClientItemsRequesting" > 
                                <WebServiceSettings Method="GetCity5" Path="_Selection.aspx" /> 
                         </telerik:RadComboBox> 

 
        [WebMethod]  
        public static RadComboBoxData GetCity5(RadComboBoxContext context)  
        {  
            RadComboBoxData comboData = new RadComboBoxData();  
            List<RadComboBoxItemData> result = new List<RadComboBoxItemData>();  
            if (context.Text != "")  
            {  
                try 
                {  
                    ComuneCollection comuneCollection = new ComuneCollection();  
 
                    string[] values;  
                    values = context.Text.Trim().Split(' ');  
                    Where w;  
                    foreach (string item in values)  
                    {  
                        if (item != null && item.Trim() != string.Empty)  
                        {  
                            w = new Where();  
                            w.Comparison = Comparison.Like;  
                            w.ColumnName = Comune.Columns.Descrizione;  
                            w.ParameterValue = "%" + item + "%";  
                            if ((bool)context["checked"])  
                                w.Condition = Where.WhereCondition.OR;  
                            else 
                                w.Condition = Where.WhereCondition.AND;  
                            comuneCollection.Where(w);  
                        }  
                    }  
 
                    comuneCollection.Load();  
 
                    if (comuneCollection.Count <= 1000)  
                    {  
 
                        foreach (Comune comune in comuneCollection)  
                        {  
                            RadComboBoxItemData itemData = new RadComboBoxItemData();  
                            itemData.Text = comune.Descrizione;  
                            itemData.Value = comune.Codprovincia + comune.Codcomune;  
 
                            if (comune.Codcatastale.Trim() == string.Empty)  
                                comune.Codcatastale = "ZZZ";  
 
                            itemData.Attributes.Add("Codcatastale", comune.Codcatastale);  
                            result.Add(itemData);  
                        }  
 
                        comboData.Message = String.Format("Trovati <b>{0}</b> elementi per <b>'{1}'</b>",  
                                                            comuneCollection.Count.ToString(),  
                                                            context.Text);  
                    }  
                    else 
                    {  
                        comboData.Message = String.Format("Trovati più di <b>1000</b> elementi. Affinare la ricerca");  
                    }  
 
                }  
                catch (Exception ex)  
                {  
                    comboData.Message = String.Format("<b>{0}</b>", ex.Message);  
 
                }  
            }  
            comboData.Items = result.ToArray();  
            return comboData;  
 
        }  
 

This code is OK!!!

But if I insert ItemTemplate I have a problem.

                            <telerik:RadComboBox ID="radCombo5"   
                                                 runat="server"   
                                                 Width="250px"   
                                                 Height="150px" 
                                                 DropDownWidth="298px" 
                                                 EnableLoadOnDemand="true"   
                                                 EnableVirtualScrolling="true" 
                                                 MarkFirstMatch="false" 
                                                 HighlightTemplatedItems="true" 
                                                 EmptyMessage="Digitare il comune da ricercare" 
                                                 OnClientItemsRequesting="radCombo5_OnClientItemsRequesting" > 
                                <WebServiceSettings Method="GetCity5" Path="_Selection.aspx" /> 
                                <HeaderTemplate> 
                                    <table style="width: 275px" cellspacing="0" cellpadding="0">  
                                        <tr> 
                                            <td style="width: 177px;">  
                                                Comune</td> 
                                            <td style="width: 60px;">  
                                                CodIstat</td> 
                                            <td style="width: 40px;">  
                                                CodCatasto</td> 
                                        </tr> 
                                    </table> 
                                </HeaderTemplate> 
                                <ItemTemplate> 
                                    <table style="width: 275px" cellspacing="0" cellpadding="0">  
                                        <tr> 
                                            <td style="width: 177px;">  
                                                <%# DataBinder.Eval(Container, "Text")%> 
                                            </td> 
                                            <td style="width: 60px;">  
                                                <%# DataBinder.Eval(Container, "Value")%> 
                                            </td> 
                                            <td style="width: 40px;">  
                                                <%# DataBinder.Eval(Container, "Attributes['Codcatastale']")%> 
                                            </td> 
                                        </tr> 
                                    </table> 
                                </ItemTemplate> 
                                  
 
                                  
                            </telerik:RadComboBox> 

The HeaderTemplate is ok.
But the ItemTemplate isn't apply, the Items are displayed in defualt mode.

Is It possibile apply Template on Item On ajax binding?
Thanx



1 Answer, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 11 Mar 2010, 03:17 PM
Hi Claudio,

RadComboBox does not support client-side Templates.

Fortunately the upcoming ASP.NET AJAX 4.0 will support such and RadComboBox will be able to take advantage of them.

Here is a blog post describing how you can achieve this with the fourth Preview of ASP.NET AJAX 4.0. Since the current Preview (preceding the official version) is the 6th one you can use the following code to instantiate the Template with it:
var template = new Sys.UI.Template($get("myTemplate"));
template.instantiateIn(item.get_element(), null, dataItem);

So, you can use all of the code in the aforementioned blog post except the Template instantiating part. Then you can then use the code above instead of that part.

Finally you can download the sixth Preview of ASP.NET AJAX 4.0 from here.

Kind regards,
Simon
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
ComboBox
Asked by
GD
Top achievements
Rank 1
Answers by
Simon
Telerik team
Share this question
or