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

[Solved] RadComboBox in a User Control not binding to data

7 Answers 407 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 09 Dec 2009, 12:40 AM
As a workaround to this thread post with no replies I'm trying to put a RadComboBox into a user control.  However, the combo box data events arent being fired like the ItemCreated event.  The data source is binding, but the combo box ends up empty when it loads. 

The user control (I left out the javascript).  
            <telerik:RadComboBox ID="RadComboBox1" Runat="server"  
                EmptyMessage="Set Team and Coach Access" AllowCustomText="true" 
                DataTextField="Person" OnClientDropDownClosed="onDropDownClosing" 
                HighlightTemplatedItems="True" ItemCreated="RadComboBox1_ItemCreated" 
                Width="214px"
                        <ExpandAnimation Type="OutElastic" Duration="300" /> 
                        <CollapseAnimation Type="InElastic" Duration="200" /> 
                        <ItemTemplate> 
                            <div onclick="StopPropagation(event)" class="combo-item-template"
                                <asp:CheckBox runat="server" ID="chk1" Checked="false" onclick="onCheckBoxClick(this)"/> 
                                <asp:Label runat="server" ID="Label1" AssociatedControlID="chk1" Text='<%# Eval("Person") %>'
                                </asp:Label> 
                            </div> 
                        </ItemTemplate>                 
            </telerik:RadComboBox> 
            <p> 
                <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' 
                                        runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>&nbsp; 
                <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button>            
            </p> 
          </div> 
           
            <asp:XmlDataSource ID="XmlDataSource1" runat="server" OnDataBinding="BindData"  
                DataFile="~/TestDataSources/AccessList.xml"></asp:XmlDataSource>      

The user control code behind
 
        public void BindData(object sender, EventArgs e) 
        { 
            base.OnDataBinding(e); 
        } 
 
        protected void RadComboBox1_ItemCreated(object sender, RadComboBoxItemEventArgs e) 
        { 
            RadComboBoxItem newItem = e.Item; 
            if (newItem.Text == "Paris") 
                newItem.Enabled = false
        } 


The .net page below is what puts this user control above into a RadGrid EditFormSettings.  Its connected to a master page which wraps a ContentPlaceHolder with a RadAjaxPanel.
        <telerik:RadGrid ID="RadGrid1" runat="server"  
            AllowPaging="True" AllowSorting="True" GridLines="None"  
            ShowGroupPanel="True" Width="795px" Style="margin-left:15px;" 
        DataSourceID="XmlDataSource2" AutoGenerateDeleteColumn="True" ShowStatusBar="true" 
            AutoGenerateEditColumn="True" > 
                <MasterTableView autogeneratecolumns="False" EditMode="PopUp" CommandItemDisplay="Top"  
                datasourceid="XmlDataSource2"
                    <NoRecordsTemplate> 
                         <div>No journal entries exist yet.  Click "Add new record" above.</div> 
                    </NoRecordsTemplate>                 
                    <RowIndicatorColumn> 
                        <HeaderStyle Width="20px"></HeaderStyle> 
                    </RowIndicatorColumn> 
                    <ExpandCollapseColumn> 
                        <HeaderStyle Width="20px"></HeaderStyle> 
                    </ExpandCollapseColumn> 
                    <commanditemsettings addnewrecordtext="Add new Journal entry" /> 
                    <Columns> 
                        <telerik:GridBoundColumn DataField="Title" HeaderText="Title"  
                SortExpression="Title" UniqueName="Title"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="Private" HeaderText="Private"  
                SortExpression="Private" UniqueName="Private"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="Replies" HeaderText="Replies"  
                SortExpression="Replies" UniqueName="Replies"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="Created" HeaderText="Created"  
                SortExpression="Created" UniqueName="Created"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="LastReply" HeaderText="LastReply"  
                            SortExpression="LastReply" UniqueName="LastReply"
                        </telerik:GridBoundColumn> 
                    </Columns> 
                    <EditFormSettings EditFormType="WebUserControl"  
                        UserControlName="../../UserControls/Forms/Journal.ascx"  
                        InsertCaption="New Journal Entry" PopUpSettings-Modal="true"  
                        CaptionFormatString="Journal Entry On {0}" 
                CaptionDataField="Created" > 
                        <EditColumn UniqueName="EditCommandColumn1"></EditColumn> 
 
<PopUpSettings Modal="True"></PopUpSettings> 
                    </EditFormSettings>                 
                </MasterTableView> 
                <clientsettings allowdragtogroup="True"
                </clientsettings> 
            </telerik:RadGrid> 

So the hierarchy is
MasterPage - RadAjax Panel - ConentPlaceholder - asp.net page - RadGrid - EditForm - UserControl


7 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 11 Dec 2009, 11:59 AM
Hello Marc Miles,

The ItemCreated event fires for already added to RadComboBox Items. In your case the RCB does not have any Items and the ItemCreated event will not fire.

If you want to bind the RCB to the XmlDataSource you can set its DataSourceID to XmlDataSource1. Then when the Grid enters Edit mode the RCB will bind to the data source automatically and your code in the ItemCreated event handler will execute.

Best wishes,
Simon
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.
0
Marc
Top achievements
Rank 1
answered on 11 Dec 2009, 07:37 PM
I actually tried exactly just that before creating this ticket which lead me to trying to trap the databinding events.

So, files are attached.  My combobox bound to the xmldatasource isn't getting populated.  The good news is, XmlDataSource1 does actually load the xml and the combobox works if it stands alone outside of the grid.  For some reason, inside a .ascx within a grid it doesn't get populated.
0
Simon
Telerik team
answered on 14 Dec 2009, 10:15 AM
Hello Marc Miles,

Thank you for providing the files.

I assembled a simple project to test the case and it worked as expected. Please see the project - I attached it to this post. Is there any difference in the configuration in your real project?

Sincerely yours,
Simon
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.
0
Marc
Top achievements
Rank 1
answered on 14 Dec 2009, 09:21 PM
Your attachment worked, the difference between yours that works and mine that doesnt is that mine has an RadAjaxPanel wrapped around the ContentPlaceHolder in the masterpage, yours doesnt.  When I did that for yours it no longer worked like mine.
0
Simon
Telerik team
answered on 18 Dec 2009, 12:47 PM
Hi Marc Miles,

I was still unable to observe the original issue after I put a RadAjaxPanel around the ContentPlaceHolder on the page in my test project.

Is there something else I need to do in order to reproduce the issue with the empty RadComboBox?

Sincerely yours,
Simon
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.
0
Marc
Top achievements
Rank 1
answered on 18 Dec 2009, 11:29 PM
Can you repost your code?  I tried exactly that on your code and it did not work.
0
Simon
Telerik team
answered on 19 Dec 2009, 09:38 AM
Hello Marc Miles,

Yes, here is the whole project.

Please note that I have surrounded the script in the UserControl with a RadScriptBlock code so that it is properly evaluated after the AJAX postback.

Greetings,
Simon
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.
Tags
ComboBox
Asked by
Marc
Top achievements
Rank 1
Answers by
Simon
Telerik team
Marc
Top achievements
Rank 1
Share this question
or