Load On Demand RadComboBox inside an EditItemTemplate of RadGrid

Thread is closed for posting
29 posts, 1 answers
  1. Answer
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 18 Aug 2010 Link to this post

    Requirements

    RadControls version RadComboBox for ASP.NET AJAX
    .NET version 2.0+
    Visual Studio version VS 2005/2008/2010
    programming language C#/VB.NET
    browser support

    all browsers supported by RadControls


    PROJECT DESCRIPTION
    This sample project demonstrates how to preselect an item in RadComboBox with Load-On-Demand enabled and nested within the EditItemTemplate of RadGrid (or other parent databound control).

    THE ISSUE
    RadComboBox with Load-On-Demand enabled is often nested in EditItemTemplate of RadGrid or another data-bound control. 
    However preselecting a RadComboBoxItem at EditItemTemplate of the parent control in such scenario is a tricky task. Sometimes developers try to set the SelectedValue property of the RadComboBox via declarative databinding and receive this error: “Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.” 

    Please note that when the RadComboBox with Load-On-Demand feature initially loads - it is empty and it has no items. Load-On-Demand fires and populates the control with data when user types in the input area or clicks on the drop-down toggle image (if there are no items in the RadComboBox).  
    That is why when the parent control enters “Edit” mode – there are no items at the RadComboBox and trying to preselect an item raises an error.

    THE SOLUTION
    We can overcome this issue by handling the RadGrid.OnItemDatabound event and creating an initial RadComboBoxItem to be displayed at the control input. 

    [C#]
    protected void OnItemDataBoundHandler(object sender, GridItemEventArgs e)
    {
        if (e.Item.IsInEditMode)
        {
            GridEditableItem item = (GridEditableItem)e.Item;
            if (!(e.Item is IGridInsertItem))
            {
                RadComboBox combo =
                      (RadComboBox)item.FindControl("RadComboBox1");
                RadComboBoxItem preselectedItem = new RadComboBoxItem();
                preselectedItem.Text = item["CategoryName"].Text;
                preselectedItem.Value = item["CategoryID"].Text;
                combo.Items.Insert(0, preselectedItem);
                combo.SelectedIndex = 0;
     
            }
        }
    }

    [VB.NET]
    Protected Sub OnItemDataBoundHandler(ByVal sender As Object, ByVal e As GridItemEventArgs)
     
            If e.Item.IsInEditMode Then
                Dim item As GridEditableItem =
                    DirectCast(e.Item, GridEditableItem)
     
                If Not (TypeOf e.Item Is IGridInsertItem) Then
     
                    Dim combo As RadComboBox =
                   DirectCast(item.FindControl("RadComboBox1"), RadComboBox)
     
                    Dim preselectedItem As New RadComboBoxItem()
                    preselectedItem.Text = item("CategoryName").Text
                    preselectedItem.Value = item("CategoryID").Text
                    combo.Items.Insert(0, preselectedItem)
                    combo.SelectedIndex = 0
                End If
     
            End If
        End Sub

    When we delete the text initially displayed at RadComboBox input - Load-On-Demand will fire and will populate the control dropdown with items.

    In order to perform Add, Edit and Delete operation handle RadGrid.OnInsertCommandRadGrid.OnUpdateCommand and RadGrid.OnDeleteCommand events and obtain the RadComboBox selected value:
    [C#]
    protected void RadGrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
      
        GridEditableItem editedItem = e.Item as GridEditableItem;
        RadComboBox comboBox = (RadComboBox)editedItem.FindControl("RadComboBox1");
      
        SqlDataSource1.UpdateParameters.Add(
            new Parameter("CategoryID", DbType.Int32, comboBox.SelectedValue));
      
        SqlDataSource1.UpdateParameters.Add(
            new Parameter("UnitPrice", DbType.Double,
                (e.Item.FindControl("UnitPriceTextBox") as TextBox).Text));
      
        SqlDataSource1.UpdateParameters.Add(
            new Parameter("ProductName", DbType.String,
                (e.Item.FindControl("ProductNameBox") as TextBox).Text));
      
        SqlDataSource1.UpdateParameters.Add(
            new Parameter("ProductID", DbType.Int32,
                (e.Item.FindControl("ProductIDBox") as TextBox).Text));
      
        SqlDataSource1.Update();
      
    }
    protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        RadComboBox comboBox = (RadComboBox)editedItem.FindControl("RadComboBox1");
      
        SqlDataSource1.InsertParameters.Add(
            new Parameter("CategoryID", DbType.Int32, comboBox.SelectedValue));
              
          ...
          ...
                ...

        SqlDataSource1.Insert();
    }
      
    protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e)
    {
        GridDataItem item = (GridDataItem)e.Item;
        string ProductID = item.OwnerTableView.DataKeyValues[item.ItemIndex]["ProductID"].ToString();
      
        SqlDataSource1.DeleteParameters.Add(
            new Parameter("ProductID", DbType.Int32, ProductID));
        SqlDataSource1.Delete();
      
    }

    [VB.NET]
    Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs)
      
        Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
        Dim comboBox As RadComboBox = DirectCast(editedItem.FindControl("RadComboBox1"), RadComboBox)
      
        SqlDataSource1.UpdateParameters.Add(New Parameter("CategoryID", DbType.Int32, comboBox.SelectedValue))
      
        SqlDataSource1.UpdateParameters.Add(New Parameter("UnitPrice", DbType.[Double], TryCast(e.Item.FindControl("UnitPriceTextBox"), TextBox).Text))
      
        SqlDataSource1.UpdateParameters.Add(New Parameter("ProductName", DbType.[String], TryCast(e.Item.FindControl("ProductNameBox"), TextBox).Text))
      
        SqlDataSource1.UpdateParameters.Add(New Parameter("ProductID", DbType.Int32, TryCast(e.Item.FindControl("ProductIDBox"), TextBox).Text))
      
        SqlDataSource1.Update()
      
    End Sub
    Protected Sub RadGrid1_InsertCommand(ByVal sender As Object, ByVal e As GridCommandEventArgs)
        Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
        Dim comboBox As RadComboBox = DirectCast(editedItem.FindControl("RadComboBox1"), RadComboBox)
      
        SqlDataSource1.InsertParameters.Add(New Parameter("CategoryID", DbType.Int32, comboBox.SelectedValue))

          ...
          ...
                ...

        SqlDataSource1.Insert()
      
    End Sub
      
    Protected Sub RadGrid1_DeleteCommand(ByVal source As Object, ByVal e As GridCommandEventArgs)
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim ProductID As String = item.OwnerTableView.DataKeyValues(item.ItemIndex)("ProductID").ToString()
        SqlDataSource1.DeleteParameters.Add(New Parameter("ProductID", DbType.Int32, ProductID))
        SqlDataSource1.Delete()
      
    End Sub


    The same approach can be used to nest Load-On-Demand RadComboBox in EditItemTemplate of FormView or GridView – please find more details at the sample project attached. Passing the update parameters is implemented using ControlParameters (at the FormView example) and SessionParameter(GridView example).
  2. 3453A8FC-CE1C-4D93-B698-B9184D36F1B6
    3453A8FC-CE1C-4D93-B698-B9184D36F1B6 avatar
    2 posts
    Member since:
    Oct 2009

    Posted 16 Nov 2010 Link to this post

    how to acheive this in RadListView instead of grid?
  3. AF5263B7-25C9-4A11-BC89-904159663126
    AF5263B7-25C9-4A11-BC89-904159663126 avatar
    918 posts
    Member since:
    Dec 2013

    Posted 23 Nov 2010 Link to this post

    Hi Phil Avella,

    I prepared a sample for you in order to demonstrate how to preselect an item in RadComboBox with Load-On-Demand enabled and nested within the EditItemTemplate of RadListView.
    In fact the approach is basically the same as the one used in the Code Library project published above.
    You simply have to handle the OnItemDataBound event of the RadListView and set the RadComboBox preselected item within the event handler.
    Additionally please handle the OnItemInserting, OnItemUpdating and OnItemDeleting events in order to pass the parameters necessary for performing insert/update and delete operations.

    All the best,
    Kalina
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  4. A9BF8E9B-A2D0-453B-AE63-0FDA5C2E31AC
    A9BF8E9B-A2D0-453B-AE63-0FDA5C2E31AC avatar
    20 posts
    Member since:
    Jan 2009

    Posted 01 Jul 2011 Link to this post

    Hi There I think this is a great article and am using it in my latest project. But I have a problem.

    I am using the 

    Protected Sub rcb_vehicleModel_ItemsRequested(ByVal sender As Object, ByVal e As RadComboBoxItemsRequestedEventArgs)
     
            Dim comboBox As RadComboBox = DirectCast(sender, RadComboBox)
     
            Dim dv As DataView = DirectCast(sqlds_vehicleModel.Select(DataSourceSelectArguments.Empty), DataView)
     
            comboBox.DataSource = dv
            comboBox.DataBind()

    'NOW I NEED TO CLEAR THE BELOW COMBO

     Dim cmdItem As GridItem = RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)(0)
            Dim ddl As DropDownList = TryCast(cmdItem.FindControl("rcb_vehicleModel"), DropDownList)
            ddl.Items.Clear()

    *****DOES NOT WORK????
     
     End Sub


    event to load my combo and everything works fine. 
    
    But I need to clear some combos below as the selection, if altered in the to box, needs to be re-selected.
    
    Sounds simple but from the above Items Requested I cannot find the other combos in the edit template.
    
    Any suggestions...
    
    Marcus
  5. AF5263B7-25C9-4A11-BC89-904159663126
    AF5263B7-25C9-4A11-BC89-904159663126 avatar
    918 posts
    Member since:
    Dec 2013

    Posted 14 Jul 2011 Link to this post

    Hello Marcus,


    I am not sure that I understand the issue.
    Why do you cast the RadComboBox "rcb_vehicleModel" to ASP.NET DropDownList(these two controls are absolutely different)?

    Greetings,
    Kalina
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  6. 54B4022F-0C8A-443F-BE69-BD7B0BAD4BBB
    54B4022F-0C8A-443F-BE69-BD7B0BAD4BBB avatar
    12 posts
    Member since:
    Jul 2012

    Posted 28 Sep 2011 Link to this post

    Could you please show a sample project using a LoadOnDemand RadComboBox in a EditItemTemplate of a DetailsView control?
    Thank you. 
  7. 54B4022F-0C8A-443F-BE69-BD7B0BAD4BBB
    54B4022F-0C8A-443F-BE69-BD7B0BAD4BBB avatar
    12 posts
    Member since:
    Jul 2012

    Posted 29 Sep 2011 Link to this post

    Could you please show how to achieve this in a DetailsView instead of RadGrid?

    Thank you. 
  8. AF5263B7-25C9-4A11-BC89-904159663126
    AF5263B7-25C9-4A11-BC89-904159663126 avatar
    918 posts
    Member since:
    Dec 2013

    Posted 03 Oct 2011 Link to this post

    Hello License Developer,

    The approach that you need to follow has been already implemented in the "FormView" sample page of the CodeLibrary project attached above.

    At first you have to handle the DetailsView.DataBound event and create an initial RadComboBoxItem to be displayed at the control input:
    protected void DetailsView1_DataBound(object sender, EventArgs e)
    {
        if(((DetailsView)sender).CurrentMode== DetailsViewMode.Edit)
        {
            DataRowView rowView =
                (DataRowView)((System.Web.UI.WebControls.DetailsView)(sender)).DataItem;
     
            RadComboBox combo =
                (RadComboBox)((System.Web.UI.WebControls.DetailsView)(sender)).FindControl("RadComboBox1");
            RadComboBoxItem preselectedItem = new RadComboBoxItem();
            preselectedItem.Text = rowView["CategoryName"].ToString();
            preselectedItem.Value = rowView["CategoryID"].ToString();
            combo.Items.Insert(0, preselectedItem);
            combo.SelectedIndex = 0;
        }
    }

    Then you can pass the update parameters to the SQLDataSource  in this way:
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind %>"
        SelectCommand="SELECT  P.ProductID,  P.ProductName, P.CategoryID, P.UnitPrice, C.CategoryName FROM Categories C INNER JOIN Products P  ON C.CategoryID = P.CategoryID ORDER BY  P.ProductID ASC "
        UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [CategoryID] = @CategoryID, [UnitPrice] = @UnitPrice WHERE [ProductID] = @ProductID">
        <UpdateParameters>
            <asp:ControlParameter ControlID="DetailsView1" Name="ProductID" PropertyName="DataKey.Values['ProductID']"
                Type="String" />
            <asp:ControlParameter ControlID="DetailsView1" Name="ProductName" PropertyName="DataKey.Values['ProductName']"
                Type="String" />
            <asp:ControlParameter ControlID="DetailsView1$RadComboBox1" Name="CategoryID" PropertyName="SelectedValue"
                Type="String" />
            <asp:ControlParameter ControlID="DetailsView1" Name="CategoryName" PropertyName="DataKey.Values['CategoryName']"
                Type="String" />
            <asp:ControlParameter ControlID="DetailsView1" Name="UnitPrice" PropertyName="DataKey.Values['UnitPrice']"
                Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>

    Please find the sample attached for further details.

    Greetings,
    Kalina
    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
  9. C25C3FF6-70FD-4CFE-8B81-613471A436F0
    C25C3FF6-70FD-4CFE-8B81-613471A436F0 avatar
    1 posts
    Member since:
    Jul 2012

    Posted 19 Jul 2012 Link to this post

    Hello,

    I am having issues with the RadComboBox as well.  I implemented this sample using the webservice example:

    http://demos.telerik.com/aspnet-ajax/combobox/examples/populatingwithdata/autocompletesql/defaultcs.aspx 

    My issue is that the selected value after the first selection never changes.  It seems to cache the first selection.  Its in an update panel there is a script manager.  Any help would be appreciated?


    Below are the code snippets for setup:

    <asp:scriptmanagerproxy runat="server" id="proxy">
            <services>
                <asp:servicereference path="~/Services/FacilityService.asmx" />
            </services>
        </asp:scriptmanagerproxy>


        <asp:updatepanel runat="server" id="upd">
            <triggers>
                <asp:AsyncPostBackTrigger controlid="radClinics" />
            </triggers>
            <contenttemplate>
                <div id="toolbox_container">
                    <div id="toolbox">
                        <div class="page_title">
                            Please provide us information specific to your location:
                        </div>
                        <div id="contentwrapper">
                            <div id="contentcolumn">
                                <div class="innertube">
                                    <div id="form_table">
                                        <div class="form_segment_item">
                                            <div class="form_label_container">
                                                Facility:</div>
                                            <div class="form_label_container">
                                                <telerik:radcombobox id="radClinics" runat="server" emptymessage="type here" width="300px"
                                                    dropdownwidth="450px" height="200px" 
                                                    onselectedindexchanged="radClinics_SelectedIndexChanged" autopostback="true" OnItemsRequested="radClinics_OnItemsRequested"
                                                    enableloadondemand="true" showmoreresultsbox="true" enablevirtualscrolling="true" >
                                                    <webservicesettings method="GetFacilities" path="~/Services/FacilityService.asmx" />
                                                </telerik:radcombobox>
                                                <a class="tooltip">
                                                    <img src="../../Assets/Images/icon-help.png" /><em></em><b>Your Facility can be found in the list to the left. Select the list and begin typing and we'll find the right one for you.</b></a>
                                            </div>
                                        </div>



  10. D9EBFAE6-999E-4CA6-8ACF-39CBC78FFF27
    D9EBFAE6-999E-4CA6-8ACF-39CBC78FFF27 avatar
    128 posts
    Member since:
    Jun 2010

    Posted 24 Jul 2012 Link to this post

    You should check your page for java script errors.
    Then make sure your Ajax settings are correct.
  11. 4F5C8753-EB0A-442D-BFF7-9868860391B7
    4F5C8753-EB0A-442D-BFF7-9868860391B7 avatar
    2 posts
    Member since:
    Jan 2013

    Posted 24 Jan 2013 Link to this post

    I am using 2 RadComboBoxes(ddlProductCategory and ddlProductCriterion) inside a RadGrid which is inside a RadPanelItem. The second combo box is filled manually when the user selects any option from the first combo box. The first one is bounded to a sqlDataSource; the second one is filled using a data reader. There is no problem inserting data and displaying it in the Rad Grid. However, I keep having errors when I try to Edit any existing record. I have read several forums and have tried to apply the logic but I still have the following error:

    “Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Selection out of range. Parameter name: value”

    I have tried already to use the ItemDataBound event to pre-populate the radComboBox:

    if (e.Item.IsInEditMode)

    {

    GridEditableItem item = (GridEditableItem)e.Item;

    if (!(e.Item is IGridInsertItem))

    {

    RadComboBox combo =(RadComboBox)item.FindControl("ddlProductCriterion");

    RadComboBoxItem preselectedItem = new RadComboBoxItem();

    preselectedItem.Text = item["Criterion"].Text;

    preselectedItem.Value = item["ProductCriterionId"].Text;

    combo.Items.Insert(0, preselectedItem);

    combo.SelectedIndex = 0;

    }

    }



    //These are my combo boxes

    <telerik:GridTemplateColumn HeaderText="Product Category" UniqueName="TemplateColumnProductCategoryId" SortExpression="ProductCategoryId">

    <ItemTemplate>

    <asp:Label runat="server" ID="ProductCategoryId" Text='<%#  Eval("Category")%>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate>

    <br />

    <telerik:RadComboBox ID="ddlProductCategory" runat="server" Skin="Web20" SelectedValue='<%# Bind("ProductCategoryId") %>' DataSourceID="dsProductCategoriesJanitorial" DataTextField="Category" DataValueField="Id" AutoPostBack="true" onselectedindexchanged="ddlProductCategory_SelectedIndexChanged1">

    </telerik:RadComboBox>

    </EditItemTemplate>

    </telerik:GridTemplateColumn>

     

    <telerik:GridTemplateColumn HeaderText="Product Criterion" UniqueName="TemplateColumnProductCriterionId" SortExpression="ProductCriterionId">

    <ItemTemplate>

    <asp:Label runat="server" ID="ProductCriterionId" Text='<%# Eval("Criterion")%>'> </asp:Label>&#160;

    </ItemTemplate>

    <EditItemTemplate>

    <telerik:RadComboBox ID="ddlProductCriterion" runat="server" Skin="Web20"

    SelectedValue='<%# Bind("ProductCriterionId") %>' ></telerik:RadComboBox>

    </EditItemTemplate>

    </telerik:GridTemplateColumn>

     

     

    //This is my sqlDatasource located outside any objects (at the bottom of the page)

    asp:SqlDataSource ID="dsJanitorialEq" runat="server" ConnectionString="<%$ ConnectionStrings:connLeed %>"

            DeleteCommand="DELETE FROM [JanitorialEquipment] WHERE [Id] = @Id" InsertCommand="INSERT INTO JanitorialEquipment(ProjectId, ProductName, PurchaseDate, CostPerItem, QuantityPurchased, ProductCategoryID, ProductCriterionId) VALUES (@ProjectId, @ProductName, @PurchaseDate, @CostPerItem, @QuantityPurchased, @ProductCategoryId, @ProductCriterionId)"

            SelectCommand="SELECT JanitorialEquipment.Id, JanitorialEquipment.ProjectId, JanitorialEquipment.ProductName, JanitorialEquipment.PurchaseDate, JanitorialEquipment.CostPerItem, JanitorialEquipment.QuantityPurchased, JanitorialEquipment.ProductCategoryID, JanitorialEquipment.ProductCriterionId, ProductCriterion.Criterion, ProductCategories.Category, ProductSections.Section FROM ProductSections RIGHT OUTER JOIN ProductCategories ON ProductSections.Id = ProductCategories.SectionId RIGHT OUTER JOIN JanitorialEquipment LEFT OUTER JOIN ProductCriterion ON JanitorialEquipment.ProductCriterionId = ProductCriterion.Id ON ProductCategories.Id = JanitorialEquipment.ProductCategoryID WHERE (JanitorialEquipment.ProjectId = @ProjectId)"

           

            UpdateCommand="UPDATE JanitorialEquipment SET ProductName = @ProductName, PurchaseDate = @PurchaseDate, CostPerItem = @CostPerItem, QuantityPurchased = @QuantityPurchased, ProductCategoryID = @ProductCategoryId, ProductCriterionId = @ProductCriterionId WHERE (Id = @Id)">

            <DeleteParameters>

                <asp:Parameter Name="Id" Type="Int32" />

            </DeleteParameters>

            <InsertParameters>

                <asp:QueryStringParameter Name="ProjectId" QueryStringField="projectid" />

                <asp:Parameter Name="ProductName" Type="String" />

                <asp:Parameter Name="PurchaseDate" Type="DateTime" />

                <asp:Parameter Name="CostPerItem" Type="Decimal" />

                <asp:Parameter Name="QuantityPurchased" Type="Int64" />

                <asp:Parameter Name="ProductCategoryId" Type="Int32" />

                <asp:Parameter Name="ProductCriterionId" Type="Int32" />

            </InsertParameters>

            <SelectParameters>

                <asp:QueryStringParameter Name="ProjectId" QueryStringField="projectid" />

            </SelectParameters>

            <UpdateParameters>

                <asp:Parameter Name="ProductName" Type="String" />

                <asp:Parameter Name="PurchaseDate" Type="DateTime" />

                <asp:Parameter Name="CostPerItem" Type="Decimal" />

                <asp:Parameter Name="QuantityPurchased" Type="Int64" />

                <asp:Parameter Name="ProductCategoryId" Type="Int32" />

                <asp:Parameter Name="ProductCriterionId" Type="Int32" />

                <asp:Parameter Name="Id" Type="Int32" />

            </UpdateParameters>

        </asp:SqlDataSource>

     

    I have tried debugging this and have placed a break point inside the “If” statement above. The error comes before even reaching the breakpoint.
    I have tried adding the code above in other events with no success. Do you recommend to use this code in other events? Any suggestions on how to solve this problem would be greatly appreciated. Thanks in advance!

  12. 2AE2267E-E1A7-422B-B7E6-203D82592B69
    2AE2267E-E1A7-422B-B7E6-203D82592B69 avatar
    975 posts
    Member since:
    Jun 2016

    Posted 29 Jan 2013 Link to this post

    Hello Henry,

    Could you open a new support ticket for this issue? If possible, please attach an isolated sample demonstrating the faced problem? This will allow us to investigate it locally and provide you the proper solution.


    All the best,
    Hristo Valyavicharski
    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.
  13. 2601CAC7-0FBB-4A78-8067-5DD79E96D8B3
    2601CAC7-0FBB-4A78-8067-5DD79E96D8B3 avatar
    12 posts
    Member since:
    Mar 2012

    Posted 15 Jul 2013 Link to this post

    Hello.

    I'm trying to add RadComboBox inside an EditItemTemplate of RadGrid, I'm using a WebService to load the data in the combobox  dynamically (EnableLoadOnDemand="True" )

    when I press any key in the keyboard the webservice is working correctly, then I select a specific data.
    then the data disappear!!!

    how to let the selected data stay in the combobox in the "grid DataBound" event ?? when I try to find the combobox control in the grid databound the selected data is "" ??


    any help please???


    Thanks,
    Manar
  14. 2AE2267E-E1A7-422B-B7E6-203D82592B69
    2AE2267E-E1A7-422B-B7E6-203D82592B69 avatar
    975 posts
    Member since:
    Jun 2016

    Posted 18 Jul 2013 Link to this post

    Hi Manar,

    Please read this help article. It explains in details how to keep the selected data. Same approach is used in this online demo.

    Regards,
    Hristo Valyavicharski
    Telerik
    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 the blog feed now.
  15. 80A6D6E4-8A19-4872-A3E7-3569FFF8FB54
    80A6D6E4-8A19-4872-A3E7-3569FFF8FB54 avatar
    24 posts
    Member since:
    Dec 2012

    Posted 28 Jun 2016 Link to this post

    I have tried everything in here and I still get the error.  What a frustrating effort this is. 
  16. 80A6D6E4-8A19-4872-A3E7-3569FFF8FB54
    80A6D6E4-8A19-4872-A3E7-3569FFF8FB54 avatar
    24 posts
    Member since:
    Dec 2012

    Posted 28 Jun 2016 Link to this post

    I have tried everything in here and I still get the error.  What a frustrating effort this is. 

            If e.Item.IsInEditMode Then  ''''''' THIS IS ALWAYS FALSE SO THE CODE NEVER RUNS
                Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)

                If Not (TypeOf e.Item Is IGridInsertItem) Then

                    Dim combo As RadComboBox = DirectCast(item.FindControl("RadComboBox1"), RadComboBox)

                    Dim preselectedItem As New RadComboBoxItem()
                    preselectedItem.Text = item("Status").Text
                    preselectedItem.Value = item("StatusID").Text
                    combo.Items.Insert(0, preselectedItem)
                    combo.SelectedIndex = 0
                End If

            End If
        End Sub

  17. 11B81D5D-1EA0-4CB3-AB67-4DAD6414022C
    11B81D5D-1EA0-4CB3-AB67-4DAD6414022C avatar
    1242 posts
    Member since:
    Apr 2022

    Posted 30 Jun 2016 Link to this post

    Hello Kim,

    Attached you will find an updated version of the Code library discussed. The only thing I have done was to change the .NET version of the project to 4.5. I have tested this project with our latest official release (R2 2016 607.45) and it works as expected - "If e.Item.IsInEditMode" returns true, when entering edit mode for one of the grids entries.

    Regards,
    Veselin Tsvetanov
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  18. 4A5750AB-380C-49FB-8AB6-CAE03B2637B0
    4A5750AB-380C-49FB-8AB6-CAE03B2637B0 avatar
    6 posts
    Member since:
    Oct 2015

    Posted 15 Aug 2017 Link to this post

    I have tried all your examples, i am using a Radlistview with a combobox inside. When the page load, i click on edit the combobox binds to my SQL data for Field City and displays it. Also I can go further and if i click on down arrow of combo box i produce i City Listing also from SQL data.

     My Issue is that after i select either the exsistng City or a new city from the dropdown list and click update, no errors but my selected City does not get updated.

    I dont have any errors so i dont know where its failing.

  19. 4A5750AB-380C-49FB-8AB6-CAE03B2637B0
    4A5750AB-380C-49FB-8AB6-CAE03B2637B0 avatar
    6 posts
    Member since:
    Oct 2015

    Posted 15 Aug 2017 in reply to 4A5750AB-380C-49FB-8AB6-CAE03B2637B0 Link to this post

    Forgot to mention, any other fields inside radlistview get updated if changed, so update is working. Just not working for Field City using radcombobox. Thanks
  20. 4A5750AB-380C-49FB-8AB6-CAE03B2637B0
    4A5750AB-380C-49FB-8AB6-CAE03B2637B0 avatar
    6 posts
    Member since:
    Oct 2015

    Posted 15 Aug 2017 in reply to 4A5750AB-380C-49FB-8AB6-CAE03B2637B0 Link to this post

    Ok got it to work !

    My issue was that i was not aware that the old textbox for City before trying to update to combobox was Visible False, it should have been deleted. Also the:

    <asp:Label ID="CityLabel2" runat="server" AssociatedControlID="RadComboBox2" Text="City"></asp:Label>

    AssociatedControlId needed to be rename to: RadComboBox2

     

    Ok, now the only issue i see is and i dont know if this is able to be done please let me know.

    If the user chooses to just enter test instead of selecting from the dropdown, and then clicks update i get this error.

    Cannot insert the value NULL into column 'City', table 'FUNERALMANAGEMENTONLINE.dbo.Funeralhomes'; column does not allow nulls. UPDATE fails.
    The statement has been terminated.

    I know what the error means, why what is typed in as text is not being saved? Thank you

     

  21. 4A5750AB-380C-49FB-8AB6-CAE03B2637B0
    4A5750AB-380C-49FB-8AB6-CAE03B2637B0 avatar
    6 posts
    Member since:
    Oct 2015

    Posted 15 Aug 2017 in reply to 4A5750AB-380C-49FB-8AB6-CAE03B2637B0 Link to this post

    Ok whooooaa....got it !

    This is my update, 

    Protected Sub RadListView1_ItemUpdating(sender As Object, e As RadListViewCommandEventArgs)

            Dim editedItem As RadListViewEditableItem = DirectCast(e.ListViewItem, RadListViewEditableItem)
            Dim comboBox As RadComboBox = DirectCast(editedItem.FindControl("RadComboBox2"), RadComboBox)
            'SqlDataSource1.UpdateParameters.Add(New Parameter("City", DbType.String, comboBox.SelectedValue))
            SqlDataSource1.UpdateParameters.Add(New Parameter("City", DbType.String, comboBox.Text))
        End Sub

    'SqlDataSource1.UpdateParameters.Add(New Parameter("City", DbType.String, comboBox.SelectedValue)) was only updating what was being binded from RadComboBox2_ItemsRequested !

    Once i commented out such and added:

    SqlDataSource1.UpdateParameters.Add(New Parameter("City", DbType.String, comboBox.Text))

    Then i was able to get selected item from RadComboBox2_ItemsRequested and also INPUT TEXT Text to get updated.

    I put this here so it can help anyone else . Thank you

  22. E4FD2021-67CE-4905-A1A0-ACF814A55512
    E4FD2021-67CE-4905-A1A0-ACF814A55512 avatar
    15 posts
    Member since:
    Dec 2017

    Posted 14 Mar 2018 in reply to 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD Link to this post

    I am trying to do this same thing for a radcombobox on the edittemplate of a RadDataForm, but it isn't quite the same.  I think I need to grab the "preselected" value from the ItemTemplate, but am not sure how to get that in the ItemDataBound event.  Can you point me in the right direction? thanks
  23. A88D69A2-4908-4BA3-9E57-13C06556B1E1
    A88D69A2-4908-4BA3-9E57-13C06556B1E1 avatar
    29 posts
    Member since:
    Nov 2008

    Posted 03 Apr 2018 in reply to E4FD2021-67CE-4905-A1A0-ACF814A55512 Link to this post

    Have you found a solution? I have the same problem and i'm not able to find a solution
  24. E4FD2021-67CE-4905-A1A0-ACF814A55512
    E4FD2021-67CE-4905-A1A0-ACF814A55512 avatar
    15 posts
    Member since:
    Dec 2017

    Posted 03 Apr 2018 in reply to A88D69A2-4908-4BA3-9E57-13C06556B1E1 Link to this post

    this is kind of a kluge but it is what I ended up with - I added a hidden field to the row in the edit template with the radcombobox that is bound to the current value.  In the pre-render event I find the hidden field and set the radcombobox.text to its value.

     

    <div class="rdfRow">
     <asp:Label ID="lblEditCounty" runat="server" AssociatedControlID="rcbCityCounty" CssClass="rdfLabel" Text="County"></asp:Label>                           
     <telerik:RadComboBox ID="rcbCityCounty" runat="server" RenderMode="Lightweight" EnableLoadOnDemand="true" AutoPostBack="true"
         OnItemsRequested="rcbCityCounty_ItemsRequested" OnPreRender="rcbCityCounty_PreRender" OnSelectedIndexChanged="rcbCityCounty_SelectedIndexChanged"
        EmptyMessage="Select a City-County"    Height="200" Width="450" DropDownWidth="600px"
          ToolTip="If a City-County pair is missing, a CRRFAdmin will have to update the City-County lookup table.">
          
     </telerik:RadComboBox>
      <asp:HiddenField runat="server" ID="hfCurrentCounty" Value='<%# Bind("County") %>' />
    </div

     

    protected void rcbCityCounty_PreRender(object sender, EventArgs e)
    {
                RadComboBox combo = sender as RadComboBox;
                HiddenField hf = combo.NamingContainer.FindControl("hfCurrentCounty") as HiddenField;
                combo.Text = hf.Value;
     }

    protected void rcbCityCounty_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)         {             RadComboBox combo = sender as RadComboBox;             HiddenField hf = combo.NamingContainer.FindControl("hfCurrentCounty") as HiddenField;             hf.Value = combo.Text;         }

     

  25. A88D69A2-4908-4BA3-9E57-13C06556B1E1
    A88D69A2-4908-4BA3-9E57-13C06556B1E1 avatar
    29 posts
    Member since:
    Nov 2008

    Posted 04 Apr 2018 in reply to E4FD2021-67CE-4905-A1A0-ACF814A55512 Link to this post

    Thanks, i thought about this trick, but i would like to find a better solution to have the possibility to bind also IsVisible or Enabled propreties. I know that i could use the same code for those properties but i try to use code behind the least possible.

     

    Thanks

  26. 48620D16-97BC-458F-9C26-E1DDFFD1FD9F
    48620D16-97BC-458F-9C26-E1DDFFD1FD9F avatar
    57 posts
    Member since:
    Oct 2018

    Posted 15 Feb 2019 in reply to E4FD2021-67CE-4905-A1A0-ACF814A55512 Link to this post

    Same Problem. Any help?
  27. 48620D16-97BC-458F-9C26-E1DDFFD1FD9F
    48620D16-97BC-458F-9C26-E1DDFFD1FD9F avatar
    57 posts
    Member since:
    Oct 2018

    Posted 15 Feb 2019 in reply to 48620D16-97BC-458F-9C26-E1DDFFD1FD9F Link to this post

    I am trying to achieve cascading dropdown scenario with the radcomboboxes in insertitemtemplate of Raddataform. Any guidance or suggestions are highly appreciable.

    Thank you. 

  28. 4513861F-C564-42D2-BC9F-5FAED19E993E
    4513861F-C564-42D2-BC9F-5FAED19E993E avatar
    4090 posts
    Member since:
    Apr 2022

    Posted 19 Feb 2019 Link to this post

    Hi Kiran,

    I've already replied to this query in your support ticket. I suggest that we continue our technical discussion in the mentioned thread.

    I will paste the reply here, too, so that it may prove helpful to other developers as well:

    "You can use the following steps to access the second combo:
    1. Access the first combo - Dim combo1 As RadComboBox = sender
    2. Access the data form item - Dim item As RadDataFormEditableItem = combo1.NamingContainer
    3. Access the second combo - Dim combo2 as RadComboBox = item.FindControl("cmbContainer")

    You can also check the sample provided here:
    https://www.telerik.com/support/code-library/accessing-controls-in-dataform

    For implementing related comboboxes inside editable container, I believe the samples provided in the following post will prove helpful to you:
    https://www.telerik.com/forums/radcombobox-cascading-inside-radgrid#GxsIQqyyPkqj1Za-mNbalg

    I hope this will prove helpful."

    Regards,
    Eyup
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  29. 48620D16-97BC-458F-9C26-E1DDFFD1FD9F
    48620D16-97BC-458F-9C26-E1DDFFD1FD9F avatar
    57 posts
    Member since:
    Oct 2018

    Posted 20 Feb 2019 Link to this post

    After following Eyups method of capturing the combobox control, please make sure on the client side your AutoPostBack is set to TRUE and your CausesValidation is set FALSE. 
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.