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

c#

1 Answer 76 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Esther Nirmala
Top achievements
Rank 1
Esther Nirmala asked on 12 Apr 2010, 07:59 AM

Hi,
I used the TextBoxTemplate which Nick provided.. in my code.. In my case, am creating the radcombo dynamically from code behind..  and adding the item template also dynamically from code behind. But its not displaying the values, Instead it creates text boxes with out any text.. And I want to set the the Initial value also like 'Select one'..  Its displaying "System.Data.DataRowView" in DropDown.. If I click it is displaying textboxes without text.. How can I solve this..

In designing  we can give like <asp:TextBox id="text1" runat="server" Text='<%=Eval("Name") %>' />.. Like that how to do for text box in template of rad combo in code behind c#

  class TextBoxTemplate : ITemplate  
    {  
        string ColName = "Text";  
 
        public void InstantiateIn(Control container)  
        {  
            TextBox textBox = new TextBox();  
            textBox.ID = "tabTextBox";  
            textBox.DataBinding += new EventHandler(this.txt_DataBind);  
            container.Controls.Add(textBox);  
        }  
        public void txt_DataBind(Object sender, EventArgs e)  
        {  
            TextBox txt = (TextBox)sender;  
            RadComboBoxItem radCombo = (RadComboBoxItem)txt.NamingContainer;  
                     txt.Text = DataBinder.Eval(radCombo, ColName).ToString();  
        }  
    }  
 
/*-------------- Dynamic creation of rad combo----------------*/  
 
 
   RadComboBox RadDropDownShopper = new RadComboBox();  
                        RadDropDownShopper.ID = "RadDropdownShopper" + i.ToString();  
                        RadDropDownShopper.Attributes.Add("style", "padding-top: 8px;");  
                        RadDropDownShopper.Attributes.Add("style", "padding-left: 30px;");  
                        RadDropDownShopper.ItemTemplate = new TextBoxTemplate();  
                        RadDropDownShopper.DataSource = FakeDataTable();  
                                           RadDropDownShopper.DataBind();  
("Select Shopper/Member"));  
 
                                              tdShopper.Controls.Add(RadDropDownShopper); 

Thanks in advance
Nimmi

1 Answer, 1 is accepted

Sort by
0
Vesko
Top achievements
Rank 2
answered on 13 Apr 2010, 12:34 PM
Hi Nimmi,

try calling the DataBind() method of the RadComboBoxItems instead (using a foreach loop)


foreach (RadComboBoxItem item in combo.Items) 
   item.DataBind(); 



Tags
ComboBox
Asked by
Esther Nirmala
Top achievements
Rank 1
Answers by
Vesko
Top achievements
Rank 2
Share this question
or