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

Bind RadComboBox with ItemTemplate in CodeBehind

5 Answers 481 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Farhan
Top achievements
Rank 1
Farhan asked on 04 Oct 2011, 10:03 PM

 Hi,
    I need some help with this issue, I am trying to bind a Radcombobox with an itemtemplate in Codebehind. I am binding it in codebehind in the Grids ItemDataBound event because I need to pass in the producttypeID from the grid to the Editform RadCombobox and then I can display the different products for that product Type in the combo box, but I am getting errors like 'attribute is set to null or not an object' ? Can someone please point out what to do so I can pass in the ObjectdataSource select parameters and display this correctly? your helps appreciated!

 Here is the code
ASPX:
  
 <telerik:RadComboBox ID="cboxProductsShipped" runat="server"   HighlightTemplatedItems="true" EnableLoadOnDemand="true"   Height="190px" Width="350px"
                                   >
                                    <ItemTemplate>
                                       <li class="col1">
                                            <%# DataBinder.Eval(Container.DataItem, "ProductName")%>
                                         </li>
                                         <li class="col2">
                                            <%# DataBinder.Eval(Container.DataItem, "Size")%>
                                         </li>
                                         <li class="col3">
                                            <%# DataBinder.Eval(Container.DataItem, "Quantity")%>
                                         </li>
                                    </ItemTemplate>
                                 </telerik:RadComboBox
  
  
 <asp:ObjectDataSource ID="ODSProducts" runat="server"
     TypeName="ProductBL" 
     DataObjectTypeName="DAL.Products"  
     SelectMethod="GetProductsByProductType"
   >
  </asp:ObjectDataSource>
  
  
C# 
  
protected void ProductsGrid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            try
            {
                if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
                {
                    GridEditFormItem editItem = (GridEditFormItem)e.Item;
                    RadComboBox cboxProducts = (RadComboBox)editItem.FindControl("cboxProductsShipped");
  
                    ODSProducts.SelectParameters.Add("producttype_id", ((Product)e.Item.DataItem).productType_id.ToString());
                    cboxProducts.DataSourceID = "ODSProducts";
                    cboxProducts.DataBind();
  
                
  
            }
            catch (Exception ex)
            {
                throw;
            }
        }

5 Answers, 1 is accepted

Sort by
0
Farhan
Top achievements
Rank 1
answered on 06 Oct 2011, 10:17 PM
Hi,

  Can someone from Telerik Team please respond to this? I havnt come acoss anything that I can use to solve my issue?
0
Mira
Telerik team
answered on 07 Oct 2011, 11:58 AM
Hello Farhan,

Please examine the following resources to see how to work with the select parameters for the ObjectDataSource:
Using Parameters with the ObjectDataSource Control
ObjectDataSource.SelectParameters Property

I hope this helps.

All the best,
Mira
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Farhan
Top achievements
Rank 1
answered on 07 Oct 2011, 09:14 PM

Hi Mira,

    Thanks for your reply but I dont think the problem Im having is with select parameters I think it has to do with binding the RadcomboBox with an Item template in the code behind as I mentioned in the thread subject.  I am binding the Radcombobox on the ItemDatabound event and I am getting a Telerik ajax error saying "Microsoft JScript runtime error: 'attributes' is null or not an object"  when i open the combobox on the page, I can see the radcombobox has the items but Im wondering if there is a better event on the backend to bind the radcombobox if it has an Item template so i dont get this error?  if so please can you provide a code sample. Thanks

 

0
Farhan
Top achievements
Rank 1
answered on 10 Oct 2011, 03:20 PM
Can someone from Telerik please follow up on this? I have been waiting for a couple of days for a response relevant to my issue? I really need to make some progress with it?
0
Mira
Telerik team
answered on 12 Oct 2011, 12:14 PM
Hello Farhan,

After you have allowed the load on demand of the RadComboBox, you need to preselect the item using the approach from this demo.
You can also examine the Load On Demand RadComboBox inside an EditItemTemplate of RadGrid code library for a runnable sample.

I hope this helps.

Best wishes,
Mira
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Farhan
Top achievements
Rank 1
Answers by
Farhan
Top achievements
Rank 1
Mira
Telerik team
Share this question
or