Accepting Text in griddropdowncolumn

5 posts, 1 answers
  1. Santanu Das
    Santanu Das avatar
    7 posts
    Member since:
    Mar 2010

    Posted 13 Mar 2014 Link to this post

    Hi

    I am using griddropdowncolumn to display/edit & inserting records in a Telerik grid.

    Everything works fine but I also want to use the griddropdowncolumn as a combobox also. I have changed the property
    of DropDownControlType="RadComboBox" but till then I am unable to accept text in the combo box.

    My intention is use the griddropdowncolumn as a combo box so that the users can do the following at the time of Insert / Edit

    1) Can choose the value form the dropdown OR 2) If the value is not available in the dropdown he can type the same so that I can save
    it to database.

    Given bellow is by ASPX File: (Please have a look in the code with Bold Formatting)

    <asp:SqlDataSource ID="SqlDtLedger" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConStr %>" 
            SelectCommand="Select * from Master_Accounting_Sub_Ledger where [Is_Visiable] ='Y'"  
            UpdateCommand="UPDATE Master_Accounting_Sub_Ledger SET [Ledger_ID] = @Ledger_ID, Sub_Ledger_Name = @Sub_Ledger_Name WHERE Sub_Ledger_ID = @Original_Sub_Ledger_ID"
            InsertCommand="INSERT INTO [Master_Accounting_Sub_Ledger] ([Ledger_ID],[Sub_Ledger_Name],[Entry_Type]) VALUES ( @Ledger_ID, @Sub_Ledger_Name, 'C')"
            DeleteCommand="UPDATE Master_Accounting_Sub_Ledger SET [Is_Visiable] ='N' WHERE Sub_Ledger_ID = @Original_Sub_Ledger_ID and Entry_Type <>'S'"
            OldValuesParameterFormatString="original_{0}" ConflictDetection="CompareAllValues">
            <UpdateParameters>
                <asp:Parameter Name="Original_Sub_Ledger_ID" Type="Int32" />
                <asp:Parameter Name="Ledger_ID" Type="Int32" />
                <asp:Parameter Name="Sub_Ledger_Name" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Ledger_ID" Type="Int32" />
                <asp:Parameter Name="Sub_Ledger_Name" Type="String" />
            </InsertParameters>
            <DeleteParameters>
                <asp:Parameter Name="Original_Sub_Ledger_ID" Type="Int32" />
            </DeleteParameters>
         </asp:SqlDataSource>

        <asp:SqlDataSource ID="Data_Accounting_Ledger_Name" runat="server"
         ConnectionString="<%$ ConnectionStrings:ConStr %>" 
            SelectCommand="Select * from Master_Accounting_Ledger WHERE Sub_Ledger=1" >
        </asp:SqlDataSource>

         <asp:SqlDataSource ID="Data_Accounting_District" runat="server"
         ConnectionString="<%$ ConnectionStrings:ConStr %>" 
            SelectCommand="Select District from Master_Accounting_Sub_Ledger GROUP By District" >
        </asp:SqlDataSource>
         
         <%------------grid--------------------%>
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" 
            AllowAutomaticInserts="True" AllowAutomaticUpdates="True" 
            DataSourceID="SqlDtLedger" GridLines="None" 
            AutoGenerateColumns="False" Width="800" Skin="Outlook">
            <ExportSettings IgnorePaging="true" OpenInNewWindow="true" FileName="Accural_Primary_Group">
                    <Pdf PageHeight="297mm" PageWidth="210mm" PageTitle="Primary Acounts Group" />
                    <Excel Format="Html" FileExtension="xls" />
                    <Csv ColumnDelimiter="Comma" RowDelimiter="NewLine" FileExtension="CSV" />

            </ExportSettings>
            <MasterTableView DataSourceID="SqlDtLedger" CommandItemDisplay="TopAndBottom"
             AutoGenerateColumns="False" DataKeyNames="Sub_Ledger_ID">
             <EditFormSettings>
                            <EditColumn CancelImageUrl="../image/RadControls/Grid/Skins/Default/Cancel.gif" EditImageUrl="../image/RadControls/Grid/Skins/Default/Edit.gif"
                                InsertImageUrl="../image/RadControls/Grid/Skins/Default/Insert.gif" UniqueName="EditCommandColumn"
                                UpdateImageUrl="../image/RadControls/Grid/Skins/Default/Update.gif">
                            </EditColumn>
                        </EditFormSettings>
               
                <Columns>
                    <telerik:GridEditCommandColumn  ButtonType="ImageButton" UniqueName="EditCommandColumn">
                    </telerik:GridEditCommandColumn>
                    <telerik:GridBoundColumn DataField="Sub_Ledger_ID" DataType="System.Int32" ReadOnly="True" UniqueName="Sub_Ledger_ID" Visible="false" ></telerik:GridBoundColumn>
                    <telerik:GridDropDownColumn DataSourceID="Data_Accounting_Ledger_Name" SortExpression="Ledger_ID" ListTextField="Ledger_Name" ListValueField="Ledger_ID" UniqueName="Ledger_ID" DataField="Ledger_ID" DropDownControlType="DropDownList" HeaderText="Ledger"></telerik:GridDropDownColumn>
                    <telerik:GridBoundColumn DataField="Sub_Ledger_Name" HeaderText="Sub Ledger Name" UniqueName="Sub_Ledger_Name"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Mailing_Name" HeaderText="Mailing Name" UniqueName="Mailing_Name"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Mailing_Address_1" HeaderText="Mailing Address 1" UniqueName="Mailing_Address_1"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Mailing_Address_2" HeaderText="Mailing Address 2" UniqueName="Mailing_Address_2"></telerik:GridBoundColumn>
                    <telerik:GridDropDownColumn DataSourceID="Data_Accounting_District" SortExpression="District" ListTextField="District" ListValueField="District" UniqueName="District" DataField="District" HeaderText="District" DropDownControlType="RadComboBox"></telerik:GridDropDownColumn>
                    <telerik:GridBoundColumn DataField="Pin" HeaderText="Pin / Zip" UniqueName="Pin"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Phone" HeaderText="Phone" UniqueName="Phone"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Email" HeaderText="Email" UniqueName="Email"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="CR_Days" HeaderText="Credit Days" UniqueName="CR_Days"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="CR_Limit" HeaderText="Credit Limit" UniqueName="CR_Limit"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Entry_Type" DataType="System.String" ReadOnly="True" UniqueName="Entry_Type" Visible="false" ></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Is_Visiable" DataType="System.String" ReadOnly="True" UniqueName="Is_Visiable" Visible="false" ></telerik:GridBoundColumn>
                    <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                            UniqueName="DeleteColumn" ImageUrl="../image/RadControls/Grid/Skins/Default/Delete.gif"></telerik:GridButtonColumn>

                </Columns>
                <EditFormSettings ColumnNumber="4" CaptionDataField="Sub_Ledger_Name" CaptionFormatString="Edit <h6> {0} </h6>">
                    <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                    <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White" Width="100%" />
                    <FormTableStyle CellSpacing="0" CellPadding="2" Height="80px" BackColor="White" />
                    <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                    <EditColumn ButtonType="ImageButton" InsertText="Insert" UpdateText="Update record"
                                UniqueName="EditCommandColumn1" CancelText="Cancel edit">
                     </EditColumn>
                     <FormTableButtonRowStyle HorizontalAlign="Right"></FormTableButtonRowStyle>
                </EditFormSettings>
                
            </MasterTableView>
            <ClientSettings>
                    <ClientEvents OnRowDblClick="RowDblClick" />
            </ClientSettings>

        </telerik:RadGrid>
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server"></telerik:RadWindowManager>
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Mar 2014 in reply to Santanu Das Link to this post

    Hi Santanu Das,

    If you would like to display the additional item in your dropdown list editor both on editing and insertion, you can perform this operation on ItemDataBound. You have to check whether the currently bound item is GridEditableItem and that it is in edit mode. If this condition is met, you can obtain reference to the DropDownList control through the GridDropDownListEditor for the respective column.

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
      if (e.Item is GridEditableItem && e.Item.IsInEditMode)
      {
        GridEditableItem edititem = (GridEditableItem)e.Item;
        GridEditManager editMan = edititem.EditManager;
        GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("ColumnUniqueName"));
        RadComboBox rComboBox = editor.ComboBoxControl;  
        rComboBox.AllowCustomText = true;     
      }
    }

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Santanu Das
    Santanu Das avatar
    7 posts
    Member since:
    Mar 2010

    Posted 14 Mar 2014 Link to this post

    Hi Princy

    Thanks for the quick responce

    I am using VB can you please post the code in VB, thanks for your quick answer.
  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Mar 2014 in reply to Santanu Das Link to this post

    Hi Santanu Das,

    Here is the code in VB. Let me know if any concern.

    VB:
    Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
        If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
            Dim edititem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
            Dim editMan As GridEditManager = edititem.EditManager
            Dim editor As GridDropDownListColumnEditor = DirectCast(editMan.GetColumnEditor("ColumnUniqueName"), GridDropDownListColumnEditor)
            Dim rComboBox As RadComboBox = editor.ComboBoxControl
            rComboBox.AllowCustomText = True
        End If
    End Sub

    Thanks,
    Princy
  6. Santanu Das
    Santanu Das avatar
    7 posts
    Member since:
    Mar 2010

    Posted 16 Mar 2014 in reply to Princy Link to this post

    Hi

    Thanks for your post. Its worked our for me. 
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017