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

Binding to MultiColumComboBox not work

3 Answers 81 Views
MultiColumn ComboBox
This is a migrated thread and some comments may be shown as answers.
wan
Top achievements
Rank 1
wan asked on 18 May 2011, 06:46 AM
Hi,
I want to select data from radgrid (see picture "selectdata.jpg") after that it will bind to MultiColumComboBox (see picture "multicolumcombobox.jpg") but it not work.

My code here
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<script type="text/javascript">
    function UpdateItemCountField(sender, args) {
        //set the footer text
        sender.get_dropDownElement().lastChild.innerHTML = "A total of " + sender.get_items().get_count() + " items";
    }
</script>
  
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid2_Search">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadAjaxPanel_Search_New" />
                <telerik:AjaxUpdatedControl ControlID="RadGrid2_Search" />
                <telerik:AjaxUpdatedControl ControlID="RadAjaxPanel_Footer" />
                <telerik:AjaxUpdatedControl ControlID="txtPrdtOrderNo" />
                <telerik:AjaxUpdatedControl ControlID="RadComboBox_Plan" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Runat="server" Skin="WebBlue" />
  
<table cellspacing="10" width="100%">
    <tr>
        <td class="style20"></td
        <td class="styleLbl">PrdtOrderNo: </td>
        <td class="styleTxtBox">
            <asp:TextBox ID="txtPrdtOrderNo" runat="server" Width="150px" Visible="false" ></asp:TextBox>
        </td>
        <td>
            <telerik:RadAjaxPanel ID="RadAjaxPanel_Search_New" runat="server">
                <asp:Button ID="btnSearch" runat="server" Text="¤é¹ËÒ" Width="100px" />  
                <asp:Button ID="btnNew" runat="server" Text="New" Width="100px" />
            </telerik:RadAjaxPanel>
        </td>
    </tr>
    <tr>
        <td class="style20"></td>  
        <td class="styleLbl">Plan : </td>
        <td class="styleTxtBox">
            <telerik:RadComboBox runat="server" ID="RadComboBox_Plan" Height="150px"
                Width="200px" MarkFirstMatch="true" DataSourceID="SqlDataSource_Plan" 
                DataValueField="planNo"
                EnableLoadOnDemand="true"
                HighlightTemplatedItems="true" AppendDataBoundItems="true"
                OnClientItemsRequested="UpdateItemCountField"
                OnDataBound="RadComboBox_Plan_DataBound"
                OnItemDataBound="RadComboBox_Plan_ItemDataBound"
                OnItemsRequested="RadComboBox_Plan_ItemsRequested" Skin="WebBlue">
                <Items>
                    <telerik:RadComboBoxItem Text="--Please Select--" Value="" Selected="true"/>     
                </Items>
                <HeaderTemplate>
                    <ul>
                        <li class="col1">Plan No</li>
                        <li class="col2">Plan Date</li>
                    </ul>
                </HeaderTemplate>
                <ItemTemplate>
                    <ul>
                        <li class="col1">
                            <%#DataBinder.Eval(Container.DataItem, "planNo")%></li>
                        <li class="col2">
                            <%#DataBinder.Eval(Container.DataItem, "date", "{0:dd/MM/yyyy}")%></li>
                    </ul>
                </ItemTemplate>
                <FooterTemplate>
                    A total of
                    <asp:Literal runat="server" ID="RadComboItemsCount" />
                    items
                </FooterTemplate>
            </telerik:RadComboBox>  
            <asp:SqlDataSource ID="SqlDataSource_Plan" runat="server" 
                ConnectionString="<%$ ConnectionStrings:projectConnectionString %>" 
                SelectCommand="SELECT planNo, date FROM [Plan] ORDER BY date">
            </asp:SqlDataSource>
        </td>
        <td>
            <asp:RequiredFieldValidator runat="server" 
                    ID="ReqFieldValidate_ddlPlan" ControlToValidate="RadComboBox_Plan"
                    ErrorMessage="*" ValidationGroup="ForSave" Display="Dynamic"
                    InitialValue="--Please Select--" />   
        </td>
    </tr>
</table>
  
  
<table cellspacing="10" width="100%">    
    <tr>
        <td class="style20"></td
        <td colspan="2">
            <telerik:RadGrid ID="RadGrid2_Search" runat="server" 
                    AllowAutomaticDeletes="True"
                    AllowAutomaticUpdates="True" DataSourceID="SqlDataSource2_Search"
                    AllowAutomaticInserts="True"  
                    AutoGenerateColumns="False"  
                    GridLines="None" Width="100%" Skin="WebBlue">
                <ClientSettings EnablePostBackOnRowClick="true" EnableRowHoverStyle="true">
                    <Selecting AllowRowSelect="true" />
                </ClientSettings>
                <MasterTableView DataKeyNames="prdtOrderNo, planNo, planDate, date, productNo, productName, qtyPrdtOrder, qtyProduce, status, remark" 
                        DataSourceID="SqlDataSource2_Search"
                        NoMasterRecordsText="No records to display."
                        AutoGenerateColumns="false" Name="ProductionOrder_Search">
                    <Columns>
                        <telerik:GridBoundColumn DataField="prdtOrderNo" DefaultInsertValue="" 
                            HeaderText="prdtOrderNo" SortExpression="prdtOrderNo" 
                            UniqueName="prdtOrderNo" ReadOnly="True" Display="false">
                        </telerik:GridBoundColumn>                   
                        <telerik:GridBoundColumn DataField="planNo" DefaultInsertValue="" 
                            HeaderText="planNo" SortExpression="planNo" 
                            UniqueName="planNo" ReadOnly="True">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="planDate" DefaultInsertValue="" 
                            HeaderText="planDate" SortExpression="planDate" UniqueName="planDate"
                            DataFormatString="{0:dd/MM/yyyy}">
                        </telerik:GridBoundColumn>                        
                        <telerik:GridBoundColumn DataField="date" DefaultInsertValue="" 
                            HeaderText="date" SortExpression="date" UniqueName="date"
                            DataFormatString="{0:dd/MM/yyyy}">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="productName" DefaultInsertValue="" 
                            HeaderText="productName" SortExpression="productName" UniqueName="productName">
                        </telerik:GridBoundColumn>                        
                        <telerik:GridBoundColumn DataField="qtyPrdtOrder" DefaultInsertValue="" 
                            HeaderText="qtyPrdtOrder" SortExpression="qtyPrdtOrder" UniqueName="qtyPrdtOrder" 
                            ItemStyle-HorizontalAlign="Right" DataFormatString="{0:N}">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="qtyProduce" DefaultInsertValue="" 
                            HeaderText="qtyProduce" SortExpression="qtyProduce" UniqueName="qtyProduce"
                            ItemStyle-HorizontalAlign="Right" DataFormatString="{0:N}">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="status" DefaultInsertValue="" 
                            HeaderText="status" SortExpression="status" UniqueName="status">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="remark" DefaultInsertValue="" 
                            HeaderText="remark" SortExpression="remark" UniqueName="remark" Visible="false">
                        </telerik:GridBoundColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
            <asp:SqlDataSource ID="SqlDataSource2_Search" runat="server" 
                ConnectionString="<%$ ConnectionStrings:projectConnectionString %>" 
                SelectCommand="SELECT ProductionOrder.prdtOrderNo, ProductionOrder.planNo, [Plan].date AS planDate, ProductionOrder.date, ProductionOrder.productNo, Product.productName, [Plan].qtyPlan, ProductionOrder.qtyPrdtOrder, ProductionOrder.qtyProduce, ProductionOrder.status, ProductionOrder.remark FROM [Plan] INNER JOIN Product ON [Plan].productNo = Product.productNo INNER JOIN ProductionOrder ON [Plan].planNo = ProductionOrder.planNo">
            </asp:SqlDataSource>
        </td>
    </tr>
</table>
  
<center>
    <telerik:RadAjaxPanel ID="RadAjaxPanel_Footer" runat="server">    
        <asp:Button ID="btnSave" runat="server" Text="Save" Width="100px" ValidationGroup="ForSave" />  
        <asp:Button ID="btnCancel" runat="server" Text="Cancel" Width="100px"/>
    </telerik:RadAjaxPanel>
</center>
  
<asp:SqlDataSource ID="SqlDataSource_ddlProduct" runat="server" 
        ConnectionString="<%$ ConnectionStrings:projectConnectionString %>" 
        SelectCommand="SELECT productNo, productName FROM Product WHERE status = 'Active'">
</asp:SqlDataSource>
  
</asp:Content>

Protected Sub RadComboBox_Plan_DataBound(ByVal sender As Object, ByVal e As EventArgs)
    'set the initial footer label
    CType(RadComboBox_Plan.Footer.FindControl("RadComboItemsCount"), Literal).Text = Convert.ToString(RadComboBox_Plan.Items.Count)
End Sub
Protected Sub RadComboBox_Plan_ItemsRequested(ByVal sender As Object, ByVal e As RadComboBoxItemsRequestedEventArgs)
    SqlDataSource_Plan.SelectCommand = "SELECT planNo, date FROM [Plan] ORDER BY date"
    RadComboBox_Plan.DataBind()
End Sub
Protected Sub RadComboBox_Plan_ItemDataBound(ByVal sender As Object, ByVal e As RadComboBoxItemEventArgs)
    'set the Text and Value property of every item
    'here you can set any other properties like Enabled, ToolTip, Visible, etc.
    e.Item.Text = Convert.ToDateTime(DirectCast(e.Item.DataItem, DataRowView)("date").ToString()).ToString("dd/MM/yyyy")
    e.Item.Value = (DirectCast(e.Item.DataItem, DataRowView))("planNo").ToString()
End Sub
Private Sub RadGrid2_Search_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid2_Search.SelectedIndexChanged
    '''' set header
    txtPrdtOrderNo.Text = RadGrid2_Search.SelectedItems(0).OwnerTableView.DataKeyValues(RadGrid2_Search.SelectedItems(0).ItemIndex)("prdtOrderNo")
    RadComboBox_Plan.SelectedValue = RadGrid2_Search.SelectedItems(0).OwnerTableView.DataKeyValues(RadGrid2_Search.SelectedItems(0).ItemIndex)("planNo")
End Sub

Thanks

3 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 18 May 2011, 04:45 PM
Hello Wan,

You should use either RadAjaxPanel or RadAjaxManager to ajaxify multiple asp:Panels. Note that it is not recommended to mix the two ajaxifying techniques, because ajaxifying RadAjaxPanels using RadAjaxManager would cause wrong update behavior.

Find more information here:
http://www.telerik.com/help/aspnet-ajax/ajax-ajaxmanager.html
http://www.telerik.com/help/aspnet-ajax/ajax-ajaxpanel.html

Kind regards,
Vasil
the Telerik team

Browse the vast support resources we have to jump start 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.

0
wan
Top achievements
Rank 1
answered on 20 May 2011, 05:22 PM
Hi,
Many thanks for your quick reply.
I do following your suggestion, but it still NOT WORK.
I try to do same with RadComboBox and it work!!!
I don't know why?
0
Vasil
Telerik team
answered on 25 May 2011, 12:26 PM
Hello Wan,

In the RadGrid2_Search_SelectedIndexChanged function loop thought all elements of the RadComboBox_Plan and then compare the value of each of them with the required planNo. If the value matches then set the current item to be selected.

Dim requiredValue As String = RadGrid2_Search.SelectedItems(0).OwnerTableView.DataKeyValues(RadGrid2_Search.SelectedItems(0).ItemIndex)("planNo")
 
Dim i As Integer = 0
While i <= RadComboBox_Plan.Items.Count - 1
  If RadComboBox_Plan.Items(i).Value = requiredValue Then
    RadComboBox_Plan.Items(i).Selected = True
    Return
  End If
End While

Additionally, you could check the resources bellow:
Binding RadComboBox to ASP DataSource components
Working with Items of RadComboBox in Server Side Code

Greetings,
Vasil
the Telerik team

Browse the vast support resources we have to jump start 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.

Tags
MultiColumn ComboBox
Asked by
wan
Top achievements
Rank 1
Answers by
Vasil
Telerik team
wan
Top achievements
Rank 1
Share this question
or