How To Use RadWindow As A Dialog For GridEditing Using A DetailsView

2 posts, 0 answers
  1. jgill
    jgill avatar
    116 posts
    Member since:
    Jul 2005

    Posted 19 Oct 2009 Link to this post

    Hello,
    I am having some trouble getting a details view with a RadCombobox to work in a RadWindow that functions an an Edit Dialog for a Radgrid.  I am using the following example as a base: http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=window

    Essentially I am trying to do the same thing as the example, but my DetailsView contains a RadCombobox as one of the fields in the edit dialog.  I am having a problem with a combobox (aka drop down list) retaining the selected item in a scenario where the details view is wrapped as a user control then loaded onto the page.   The problem seems to be with using the RadCombobox in the DetailsView while also allowing the user to change the value.

    -      I have two user controls that each contains a DetailsView with a dropdownlist as a template field in the DetailsView
         o      The dropdown triggers a postback which raises an event that the page then uses to determine which user control to load depending on the value selected in the dropdown.
    -      I load one of the two different user controls onto the page depending on the value of the selected item in the dropdownlist.
         o      This seems to be working correctly as the correct user control loads depending on which value is selected in the dropdownlist within the user control
    -      Problem: However, after loading a different usercontrol/DetailsView the selected item of the drop down list is not retained (E.g. even though the correct user control/details view loaded the dropdownlist is not remembering the previously selected value).  So while the correct user control loads the selected value in the dropdown is not retained.

    Any help would be appreciated.


    ASPX Markup
    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="ItemBuilderSimpleItem.ascx.vb" Inherits="admin_UserControls_App_ItemBuilderSimpleItem" %> 
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
       
       
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        DataKeyNames="ItemID" DataSourceID="SqlDataSource1" BorderWidth="0" CellPadding="0" CellSpacing="7">  
        <Fields> 
                <asp:TemplateField HeaderText="<%$Resources: Config, ItemType %>" SortExpression="ItemTypeID">  
                         <EditItemTemplate> 
                             <telerik:RadComboBox ID="cboItemTypesDropdown" OnSelectedIndexChanged="ItemType_SelectedIndexChanged" runat="server" DataSourceID="SqlDataSource2" 
                              DataTextField="Alias" 
                              DataValueField="ItemTypeID" 
                              SelectedValue='<%#Bind("ItemTypeID") %>' AutoPostBack="true" Width="350px">  
                             </telerik:RadComboBox> 
                         </EditItemTemplate> 
                         <ItemTemplate> 
                            <asp:Label Runat="server" Text='<%# Bind("ItemTypeID") %>' ID="lblItemTypeID"></asp:Label> 
                         </ItemTemplate> 
                </asp:TemplateField> 
            <asp:BoundField DataField="Alias" HeaderText="<%$Resources: Config, Alias %>" SortExpression="Alias" ControlStyle-Width="350px" /> 
           <asp:CheckBoxField DataField="IsActive" HeaderText="<%$Resources: Config, IsActive %>" SortExpression="IsActive" /> 
            <asp:CommandField ShowEditButton="True" EditText="<%$Resources: Config, Update %>"/>  
            <asp:CommandField ShowInsertButton="True" InsertText="<%$Resources: Config, Add %>"/>  
            <asp:CommandField ShowDeleteButton="True" DeleteText="<%$Resources: Config, Delete %>" /> 
        </Fields> 
    </asp:DetailsView> 
    <br /> 
          
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:connApp_PRD %>" 
    DeleteCommand="proc_ConfigItems_Delete" 
    DeleteCommandType="StoredProcedure" 
    InsertCommand="proc_ConfigItems_Add" 
    InsertCommandType="StoredProcedure" 
    SelectCommand="proc_ConfigItems_GetItemByItemID" 
    SelectCommandType="StoredProcedure" 
    UpdateCommand="proc_ConfigItems_Update" 
    UpdateCommandType="StoredProcedure">  
                <DeleteParameters> 
                    <asp:Parameter Name="ItemID" Type="Int64" /> 
                </DeleteParameters> 
                <UpdateParameters> 
                    <asp:Parameter Name="ItemID" Type="Int64" /> 
                    <asp:Parameter Name="ItemTypeID" Type="Int64" /> 
                    <asp:Parameter Name="Alias" Type="String" /> 
                    <asp:Parameter Name="IsActive" Type="Boolean" /> 
                </UpdateParameters> 
                <InsertParameters> 
                    <asp:Parameter Name="ItemTypeID" Type="Int64" /> 
                    <asp:Parameter Name="Alias" Type="String" /> 
                    <asp:Parameter Name="IsActive" Type="Boolean" /> 
                </InsertParameters> 
                <SelectParameters> 
                    <asp:QueryStringParameter Name="ItemID" QueryStringField="ItemID" Type="Int64" /> 
                </SelectParameters> 
            </asp:SqlDataSource> 
                    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:connApp_PRD %>" 
                SelectCommand="proc_ItemTypes_GetAllItemTypes" SelectCommandType="StoredProcedure">  
            </asp:SqlDataSource> 


    VB.NET Codebehind

    Imports System  
    Imports System.Data  
    Imports System.Collections  
    Imports System.Web.UI  
    Imports Telerik.Web.UI  
       
    Imports Microsoft.ApplicationBlocks.Data  
    Imports System.Configuration  
    Imports System.Data.SqlClient  
    Imports JG.App.Core  
       
    Partial Class admin_UserControls_App_ItemBuilderSimpleItem  
        Inherits System.Web.UI.UserControl  
        Implements IItemBuilder  
       
        Private _ItemType As Integer 
       
        'Moved delegate to interface definition  
        'Public Delegate Sub ItemTypeChangedHandler(ByVal sender As Object, ByVal e As ItemTypeChangedEventArgs)  
        Public Event ItemTypeChanged(ByVal sender As ObjectByVal e As ItemTypeChangedEventArgs) Implements IItemBuilder.ItemTypeChanged  
       
            Protected Sub Page_Init(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Init  
            If Page.Request.QueryString("ItemID"Is Nothing Then 
                DetailsView1.DefaultMode = DetailsViewMode.Insert  
            Else 
                DetailsView1.DefaultMode = DetailsViewMode.Edit  
            End If 
       
        End Sub 
       
        'Add a method that resembles default methods to handle the Item type changing  
        Protected Sub ItemType_SelectedIndexChanged(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)  
            Dim control As RadComboBox = ControlUtility.Instance.FindControlRecursive("cboItemTypesDropdown")  
       
            If Not IsNothing(control) Then 
                ItemType = control.SelectedValue  
            End If 
        End Sub 
       
       
        Public Property ItemType() As Integer Implements IItemBuilder.ItemType  
            Get 
                Dim control As RadComboBox = ControlUtility.Instance.FindControlRecursive("cboItemTypesDropdown")  
                If Not IsNothing(control) Then 
                    If control.SelectedItem.Value = String.Empty Then 
                        control.SelectedIndex = -1  
                        _ItemType = Nothing 
                        MsgBox("Nothing")  
                    Else 
                        _ItemType = control.SelectedItem.Value  
                        MsgBox("2 selected item: " & _ItemType.ToString)  
                    End If 
       
                    MsgBox("3 selected item: " & _ItemType.ToString)  
       
                    Return _ItemType  
                End If 
       
            End Get 
            Set(ByVal Value As Integer)  
                Dim control As RadComboBox = ControlUtility.Instance.FindControlRecursive("cboItemTypesDropdown")  
                If Not IsNothing(control) Then 
                    If Not IsNothing(control.Items.FindItemByValue(Value)) Then 
                        control.Items.FindItemByValue(Value).Selected = True 
                        _ItemType = Value  
                        MsgBox("Do I ever get here?" & _ItemType)  
                        OnItemTypeChanged()  
                    End If 
                End If 
            End Set 
        End Property 
       
       
        Protected Sub OnItemTypeChanged()  
            RaiseEvent ItemTypeChanged(MeNew ItemTypeChangedEventArgs(_ItemType))  
        End Sub 
       
        Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
            Dim control As RadComboBox = ControlUtility.Instance.FindControlRecursive("cboItemTypesDropdown")  
            If Not IsNothing(control) Then 
                If Not IsNothing(control.Items.FindItemByValue(ItemType)) Then 
                    control.Items.FindItemByValue(ItemType).Selected = True 
                End If 
            End If 
        End Sub 
    End Class 
     
  2. Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 22 Oct 2009 Link to this post

    Hello Jonathan,

    I am afraid that the provided information is not enough for me to determine what might be the reason for the problem. I am not quite sure what control is returned by the ControlUtility.Instance.FindControlRecursive method. Also the code bellow should throw an exception when it is executed:
    ItemType = control.SelectedValue
    because the ItemType property is of type Integer, but the control.SelectedValue returns a string.
    Could you please open a new support ticket and send me a runnable project that shows your setup, including detailed explanation of the expected behavior? I will check it and do my best to provide a working solution.

    Greetings,
    Fiko
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top