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

RADComboBox in Grid

3 Answers 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Giancarlo
Top achievements
Rank 1
Giancarlo asked on 22 Jun 2012, 12:37 AM
Hi Forum,
I have a RADGrid with a RADComboBox column with EnableLoadOnDemand=true and ItemsRequest event defined.

<telerik:RadComboBox ID="cboLocalita"

EnableVirtualScrolling="true"

OnItemsRequested="cboLocalita_ItemsRequested"

ShowMoreResultsBox="true"

EnableLoadOnDemand="true"

DataTextField ="descrizione"

DataValueField ="idlocalita"

runat="server">

</telerik:RadComboBox>

Protected Sub cboLocalita_ItemsRequested(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs)
    Dim context As New JLogTabelleDataContext
    Dim allLocalita = From localita In context.localita _
     Order By localita.descrizione _
     Select localita
    If Not [String].IsNullOrEmpty(e.Text) Then
        allLocalita = From localita In context.localita _
         Where localita.descrizione.StartsWith(e.Text) _
         Order By localita.descrizione _
         Select localita
    End If
    Dim Lstlocalita = allLocalita.Skip(e.NumberOfItems).Take(10)
    CType(o, RadComboBox).DataSource = Lstlocalita
    CType(o, RadComboBox).DataBind()
    Dim endOffset As Integer = e.NumberOfItems + Lstlocalita.Count()
    Dim totalCount As Integer = allLocalita.Count()
    If endOffset = totalCount Then
        e.EndOfItems = True
    End If
    e.Message = [String].Format("Rec <b>1</b>-<b>{0}</b> Tot <b>{1}</b>", endOffset, totalCount)
End Sub

The automatic CRUD operation enabled on the Grid doesn't work, so the value of RADComboBox never change after update of then EditForm and is setted to NULL when I perform a created operation.

If I bind the Combobox to a Datasource object by the property DataSourceID and I disable EnableLoadOnDemand without implement OnItemsRequest event , CRUD works fine. I have a lot of records to show in ComboBox therefore Loading data on demand is very important.
Thanks to all for any response.
Gaetano

3 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 26 Jun 2012, 02:05 PM
Hi Gaetano,

By default, there is no problem with using load on demand RadComboBox in RadGrid with automatic operations. You can see how this is implemented here:
Grid / Combo in Grid
If you do not notice any differences, you can consider opening a support ticket and sending us the full code related to this scenario.

Regards,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Giancarlo
Top achievements
Rank 1
answered on 02 Jul 2012, 02:26 PM
Hi,
I bind RADComboBox to property "idlocalita" of the RADGrid's datasource.
At run time an exception occurs:    Selection out of range Nome parametro: value
The datasource of RadCombo is not defined declarative by property DatasourceID but in order to take advantage of the LoadOnDemand capability I defined event : onItemsRequested 
Is This the correct way?

below my aspx tag


<telerik:GridTemplateColumn DataField="localita.descrizione" HeaderText="Località" SortExpression="localita.descrizione" >
                    <HeaderStyle Width="25%" />
                    <ItemTemplate>
                        <%#Eval("localita.descrizione")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox ID="cboLocalita"
                            SelectedValue='<%# bind("idlocalita") %>'   
                            OnItemsRequested ="cboLocalita_ItemsRequested"                        
                            EnableVirtualScrolling="true"
                            ShowMoreResultsBox="true"
                            EnableLoadOnDemand="true"               
                            DataTextField ="descrizione"
                            DataValueField ="idlocalita"                                                     
                            runat="server">
                        </telerik:RadComboBox>                          
                    </EditItemTemplate>                    
                </telerik:GridTemplateColumn>

my vb code:

Protected Sub cboLocalita_ItemsRequested(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs)
 
    Dim context As New JLogTabelleDataContext
 
    Dim allLocalita = From localita In context.localita _
     Order By localita.descrizione _
     Select localita
 
    If Not [String].IsNullOrEmpty(e.Text) Then
        allLocalita = From localita In context.localita _
         Where localita.descrizione.StartsWith(e.Text) _
         Order By localita.descrizione _
         Select localita
    End If
 
    Dim Lstlocalita = allLocalita.Skip(e.NumberOfItems).Take(10)
    CType(o, RadComboBox).DataSource = Lstlocalita
    CType(o, RadComboBox).DataBind()
 
    Dim endOffset As Integer = e.NumberOfItems + Lstlocalita.Count()
    Dim totalCount As Integer = allLocalita.Count()
 
    If endOffset = totalCount Then
        e.EndOfItems = True
    End If
 
    e.Message = [String].Format("Rec <b>1</b>-<b>{0}</b> Tot <b>{1}</b>", endOffset, totalCount)
 
End Sub




0
Tsvetina
Telerik team
answered on 05 Jul 2012, 07:06 AM
Hi Gaetano,

You cannot declaratively set SelectedValue to the combo when you bind it on demand. This way it looks for a value initially that is not available (it has no items when the grid is put in edit mode). The correct approach would be to remove the SelectedValue setting from mark-up and do the selection manually only after you bind the combo in ItemsRequested event.

Regards,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Giancarlo
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Giancarlo
Top achievements
Rank 1
Share this question
or