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

[Solved] How to refrence RadComboBox when in Grid EditForm Template

9 Answers 224 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
bradley baker
Top achievements
Rank 1
bradley baker asked on 16 Oct 2009, 05:06 PM
Im trying to do some custom bindings on a combo box when its on a EditForm in a Grid.  I can make the combox work when its outside the grid but when I move it into the grid it says it cant find the refrence to the combobox???


This works perfectly when the combobox is outside of the grid, how do I make it work when its inside the grid editform template?
    Protected Sub RadComboBox1_ItemsRequested(ByVal o As ObjectByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles RadComboBox1.ItemsRequested  
        CustDropDownSQL.SelectCommand = "SELECT [CCUST], [CNME] FROM [RCM] WHERE [CMID] = 'CM' and [CNME] Like '" + e.Text + "%'  ORDER BY [CNME] ASC" 
        RadComboBox1.DataSource = CustDropDownSQL  
        RadComboBox1.DataTextField = "CNME" 
        RadComboBox1.DataValueField = "CCUST" 
        RadComboBox1.DataBind()  
    End Sub 

9 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Oct 2009, 05:44 AM
Hello Bradley,

You could try the following code instead to set the datasource of the combobox nested inside the formtemplate of the grid:
vb:
Protected Sub RadComboBox1_ItemsRequested(o As Object, e As RadComboBoxItemsRequestedEventArgs) 
    Dim combo As RadComboBox = DirectCast(sender, RadComboBox) 
    CustDropDownSQL.SelectCommand = "SELECT [CCUST], [CNME] FROM [RCM] WHERE [CMID] = 'CM' and [CNME] Like '" + e.Text + "%'  ORDER BY [CNME] ASC" 
    combo.DataSource = CustDropDownSQL 
    combo.DataTextField = "CNME" 
    combo.DataValueField = "CCUST" 
    combo.DataBind() 
End Sub 

Thanks
Princy.
0
bradley baker
Top achievements
Rank 1
answered on 19 Oct 2009, 03:43 PM
The code doesnt work.  It says RadComboBoxItemsRequestedEventArgs and RadComboBox arent defined still.

 

 
Partial Class bradford_meterset_log_Default  
    Inherits System.Web.UI.Page  
 
    Protected Sub RadComboBox1_ItemsRequested(ByVal o As ObjectByVal e As RadComboBoxItemsRequestedEventArgs)  
        Dim combo As RadComboBox = DirectCast(sender, RadComboBox)  
        CustDropDownSQL.SelectCommand = "SELECT [CCUST], [CNME] FROM [RCM] WHERE [CMID] = 'CM' and [CNME] Like '" + e.Text + "%'  ORDER BY [CNME] ASC" 
        combo.DataSource = CustDropDownSQL  
        combo.DataTextField = "CNME" 
        combo.DataValueField = "CCUST" 
        combo.DataBind()  
    End Sub 
 
End Class 

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="bradford_meterset_log_Default" %> 
 
<asp:Content ID="Content1" ContentPlaceHolderID="Header" Runat="Server">  
    <style type="text/css">  
        .style1  
        {  
            width: 90px;  
        }  
    </style> 
    <script type="text/javascript">  
        function StopRequesting(combo, args) {  
            if (combo._text.length < 4) {  
                args.set_cancel(true);  
            }  
        }  
    </script> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="PrimaryContent" Runat="Server">  
    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">  
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="MeterSetLogGrid">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="MeterSetLogGrid" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManagerProxy> 
    <h1 align="center">Bradford Meterset Log</h1><br /> 
    <asp:SqlDataSource ID="MeterSetLogSQL" runat="server"   
        ConflictDetection="CompareAllValues"   
        ConnectionString="<%$ ConnectionStrings:bfd_meterlogConnectionString %>"   
        DeleteCommand="DELETE FROM [meterset_log] WHERE [msl_id] = @original_msl_id AND [msl_custid] = @original_msl_custid AND [msl_dmd] = @original_msl_dmd AND [msl_qty] = @original_msl_qty AND [msl_sonum] = @original_msl_sonum AND [msl_serial] = @original_msl_serial AND [msl_partnum] = @original_msl_partnum AND [msl_ts] = @original_msl_ts"   
        InsertCommand="INSERT INTO [meterset_log] ([msl_custid], [msl_dmd], [msl_qty], [msl_sonum], [msl_serial], [msl_partnum]) VALUES (@msl_custid, @msl_dmd, @msl_qty, @msl_sonum, @msl_serial, @msl_partnum)"   
        OldValuesParameterFormatString="original_{0}"   
        SelectCommand="SELECT * FROM [meterset_log] ORDER BY [msl_ts] DESC"   
        UpdateCommand="UPDATE [meterset_log] SET [msl_custid] = @msl_custid, [msl_dmd] = @msl_dmd, [msl_qty] = @msl_qty, [msl_sonum] = @msl_sonum, [msl_serial] = @msl_serial, [msl_partnum] = @msl_partnum WHERE [msl_id] = @original_msl_id AND [msl_custid] = @original_msl_custid AND [msl_dmd] = @original_msl_dmd AND [msl_qty] = @original_msl_qty AND [msl_sonum] = @original_msl_sonum AND [msl_serial] = @original_msl_serial AND [msl_partnum] = @original_msl_partnum">  
        <DeleteParameters> 
            <asp:Parameter Name="original_msl_id" Type="Int32" /> 
            <asp:Parameter Name="original_msl_custid" Type="Int32" /> 
            <asp:Parameter Name="original_msl_dmd" Type="Int32" /> 
            <asp:Parameter Name="original_msl_qty" Type="Int32" /> 
            <asp:Parameter Name="original_msl_sonum" Type="Int32" /> 
            <asp:Parameter Name="original_msl_serial" Type="String" /> 
            <asp:Parameter Name="original_msl_partnum" Type="String" /> 
            <asp:Parameter Name="original_msl_ts" Type="DateTime" /> 
        </DeleteParameters> 
        <UpdateParameters> 
            <asp:Parameter Name="msl_custid" Type="Int32" /> 
            <asp:Parameter Name="msl_dmd" Type="Int32" /> 
            <asp:Parameter Name="msl_qty" Type="Int32" /> 
            <asp:Parameter Name="msl_sonum" Type="Int32" /> 
            <asp:Parameter Name="msl_serial" Type="String" /> 
            <asp:Parameter Name="msl_partnum" Type="String" /> 
            <asp:Parameter Name="original_msl_custid" Type="Int32" /> 
            <asp:Parameter Name="original_msl_dmd" Type="Int32" /> 
            <asp:Parameter Name="original_msl_qty" Type="Int32" /> 
            <asp:Parameter Name="original_msl_sonum" Type="Int32" /> 
            <asp:Parameter Name="original_msl_serial" Type="String" /> 
            <asp:Parameter Name="original_msl_partnum" Type="String" /> 
        </UpdateParameters> 
        <InsertParameters> 
            <asp:Parameter Name="msl_custid" Type="Int32" /> 
            <asp:Parameter Name="msl_dmd" Type="Int32" /> 
            <asp:Parameter Name="msl_qty" Type="Int32" /> 
            <asp:Parameter Name="msl_sonum" Type="Int32" /> 
            <asp:Parameter Name="msl_serial" Type="String" /> 
            <asp:Parameter Name="msl_partnum" Type="String" /> 
        </InsertParameters> 
    </asp:SqlDataSource> 
    <asp:SqlDataSource ID="CustDropDownSQL" runat="server"   
        ConnectionString="<%$ ConnectionStrings:ERPLXFConnectionString %>"   
        SelectCommand="SELECT [CCUST], [CNME] FROM [RCM] WHERE [CMID] = 'CM' ORDER BY [CNME] ASC"></asp:SqlDataSource> 
    <asp:SqlDataSource ID="ItemNoDropDownSQL" runat="server"   
        ConnectionString="<%$ ConnectionStrings:ERPLXFConnectionString %>"   
        SelectCommand="SELECT [ICPROD] FROM [CIC] WHERE ([ICFAC] = '010') ORDER BY [ICPROD] ASC">  
    </asp:SqlDataSource>    
      
                                
            
    <telerik:RadGrid ID="MeterSetLogGrid" runat="server"   
        AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True"   
        DataSourceID="MeterSetLogSQL" GridLines="None" ShowGroupPanel="True"   
        AllowAutomaticDeletes="True" AllowAutomaticInserts="True"   
        AllowAutomaticUpdates="True">  
<MasterTableView AutoGenerateColumns="False" DataKeyNames="msl_id"   
            DataSourceID="MeterSetLogSQL" CommandItemDisplay="Top">  
    <Columns> 
        <telerik:GridBoundColumn DataField="msl_id" DataType="System.Int32"   
            HeaderText="ID" ReadOnly="True" SortExpression="msl_id" UniqueName="msl_id">  
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="msl_custid" DataType="System.Int32"   
            HeaderText="Cust No" SortExpression="msl_custid" UniqueName="msl_custid">  
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="msl_dmd" DataType="System.Int32"   
            HeaderText="Order No" SortExpression="msl_dmd" UniqueName="msl_dmd">  
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="msl_qty" DataType="System.Int32"   
            HeaderText="Qty" SortExpression="msl_qty" UniqueName="msl_qty">  
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="msl_sonum" DataType="System.Int32"   
            HeaderText="SO No" SortExpression="msl_sonum" UniqueName="msl_sonum">  
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="msl_serial" HeaderText="Serial No(s)"   
            SortExpression="msl_serial" UniqueName="msl_serial">  
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="msl_partnum" HeaderText="Item No"   
            SortExpression="msl_partnum" UniqueName="msl_partnum">  
        </telerik:GridBoundColumn> 
        <telerik:GridDateTimeColumn DataField="msl_ts" HeaderText="Entered"   
            SortExpression="msl_ts" UniqueName="msl_ts">  
        </telerik:GridDateTimeColumn> 
        <telerik:GridEditCommandColumn UniqueName="EditColumn" ButtonType="ImageButton" HeaderStyle-Width="27px">    
<HeaderStyle Width="27px"></HeaderStyle> 
        </telerik:GridEditCommandColumn>    
        <telerik:GridButtonColumn CommandName="Delete" Text="Delete" ButtonType="ImageButton" 
            UniqueName="DeleteColumn" HeaderStyle-Width="27px">  
<HeaderStyle Width="27px"></HeaderStyle> 
        </telerik:GridButtonColumn>        
    </Columns> 
<RowIndicatorColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</RowIndicatorColumn> 
 
<ExpandCollapseColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</ExpandCollapseColumn> 
    <EditFormSettings EditFormType="Template">  
        <FormTemplate> 
            <table style="width:182%;">  
                <tr> 
                    <td class="style1">  
                        ID:</td> 
                    <td> 
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("msl_id") %>'></asp:Label> 
                    </td> 
                </tr> 
                <tr> 
                    <td class="style1">  
                        Cust No:</td> 
                    <td> 
                            <telerik:RadComboBox ID="RadComboBox1" Runat="server" AllowCustomText="True"   
                            EnableLoadOnDemand="True" onitemsrequested="RadComboBox1_ItemsRequested"   
                            onclientitemsrequesting="StopRequesting">  
                            </telerik:RadComboBox>    
 
                    </td> 
                </tr> 
                <tr> 
                    <td class="style1">  
                        Order No:</td> 
                    <td> 
                        <telerik:RadTextBox ID="RadTextBox1" Runat="server"   
                            Text='<%# Bind("msl_dmd") %>' Width="125px">  
                        </telerik:RadTextBox> 
                    </td> 
                </tr> 
                <tr> 
                    <td class="style1">  
                        QTY:</td> 
                    <td> 
                        <telerik:RadTextBox ID="RadTextBox2" Runat="server"   
                            Text='<%# Bind("msl_qty") %>' Width="125px">  
                        </telerik:RadTextBox> 
                    </td> 
                </tr> 
                <tr> 
                    <td class="style1">  
                        SO No:</td> 
                    <td> 
                        <telerik:RadTextBox ID="RadTextBox3" Runat="server"   
                            Text='<%# Bind("msl_sonum") %>' Width="125px">  
                        </telerik:RadTextBox> 
                    </td> 
                </tr> 
                <tr> 
                    <td class="style1">  
                        Serial No(s):</td> 
                    <td> 
                        <telerik:RadTextBox ID="RadTextBox4" Runat="server"   
                            Text='<%# Bind("msl_serial") %>' Width="125px">  
                        </telerik:RadTextBox> 
                    </td> 
                </tr> 
                <tr> 
                    <td class="style1">  
                        Item No:</td> 
                    <td> 
                        <telerik:RadTextBox ID="RadTextBox5" runat="server"   
                            Text='<%# Bind("msl_partnum") %>' Width="125px">  
                        </telerik:RadTextBox> 
                    </td> 
                </tr> 
                <tr> 
                    <td class="style1">  
                        Entered:</td> 
                    <td> 
                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("msl_ts") %>'></asp:Label> 
                    </td> 
                </tr>                  
                <tr> 
                                <td align="right" colspan="2">  
                                    <asp:Button ID="Button1" Text='<%# Iif (TypeOf Container is GridEditFormInsertItem, "Insert", "Update") %>' 
                                        runat="server" CommandName='<%# Iif (TypeOf Container is GridEditFormInsertItem, "PerformInsert", "Update") %>'>  
                                    </asp:Button>&nbsp;  
                                    <asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">  
                                    </asp:Button> 
                                </td> 
                            </tr> 
            </table> 
            <br /> 
        </FormTemplate> 
    </EditFormSettings> 
</MasterTableView> 
        <ClientSettings AllowDragToGroup="True">  
        </ClientSettings> 
    </telerik:RadGrid> 
 
</asp:Content> 
 
 
0
bradley baker
Top achievements
Rank 1
answered on 25 Oct 2009, 06:47 PM
Anything?  Still trying to get this to work.
0
Vesko
Top achievements
Rank 2
answered on 28 Oct 2009, 12:06 PM
You need to import the Telerik.Web.UI namespace in the .vb page:

Imports Telerik.Web.UI 

0
bradley baker
Top achievements
Rank 1
answered on 28 Oct 2009, 03:46 PM

Now the sender is not defined.

Imports Telerik.Web.UI  
Partial Class bradford_meterset_log_Default  
    Inherits System.Web.UI.Page  
 
    Protected Sub RadComboBox1_ItemsRequested(ByVal o As ObjectByVal e As RadComboBoxItemsRequestedEventArgs)  
        Dim combo As RadComboBox = DirectCast(sender, RadComboBox)  
        CustDropDownSQL.SelectCommand = "SELECT [CCUST], [CNME] FROM [RCM] WHERE [CMID] = 'CM' and [CNME] Like '" + e.Text + "%'  ORDER BY [CNME] ASC" 
        combo.DataSource = CustDropDownSQL  
        combo.DataTextField = "CNME" 
        combo.DataValueField = "CCUST" 
        combo.DataBind()  
    End Sub 
 
End Class 
0
Princy
Top achievements
Rank 2
answered on 29 Oct 2009, 06:40 AM
Hi Bradley,

You can replace 'sender' with the 'o', which is the RadComboBox object:
vb:
Imports Telerik.Web.UI    
Partial Class bradford_meterset_log_Default    
    Inherits System.Web.UI.Page    
   
    Protected Sub RadComboBox1_ItemsRequested(ByVal o As ObjectByVal e As RadComboBoxItemsRequestedEventArgs)    
        Dim combo As RadComboBox = DirectCast(o, RadComboBox) 'Replace sender with o    
        CustDropDownSQL.SelectCommand = "SELECT [CCUST], [CNME] FROM [RCM] WHERE [CMID] = 'CM' and [CNME] Like '" + e.Text + "%'  ORDER BY [CNME] ASC"   
        combo.DataSource = CustDropDownSQL    
        combo.DataTextField = "CNME"   
        combo.DataValueField = "CCUST"   
        combo.DataBind()    
    End Sub   
   
End Class   

Princy.
0
bradley baker
Top achievements
Rank 1
answered on 29 Oct 2009, 03:54 PM
Thanks its working now, but it wont insert the value to the database.  If I do
<%# Bind("Field" %> 

It comes up with an error "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."  So how do I Bind this to the field so it can be inserted to the database.
0
bradley baker
Top achievements
Rank 1
answered on 02 Nov 2009, 04:53 PM
Any ideas anyone?
0
Vesko
Top achievements
Rank 2
answered on 05 Nov 2009, 08:28 AM
You can check these links:



I hope you will get the idea.
Tags
ComboBox
Asked by
bradley baker
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
bradley baker
Top achievements
Rank 1
Vesko
Top achievements
Rank 2
Share this question
or