Problem with RadComboBox with ItemTemplate of asp:TextBox
I am using a RadComboBox with an ItemTemplate that contains 50 TextBox controls that a user can enter information into. I add the 50 TextBox controls dynamically (see below). When information is entered into the textboxes, it appears that everything is working as expected. However, when I iterate the collection of TextBoxes, the data is not there. Here is my code:
aspx page:
<telerik:RadComboBox ID="ddlListItemsQ1" runat="server" Width="200px" ShowDropDownOnTextboxClick="true" EnableEmbeddedSkins="false" Skin="Classic" TabIndex="2" ZIndex="100" disabled="true" OnClientDropDownOpening="OnDropdownListItemsOpening">
<ItemTemplate>
<asp:TextBox ID="txtBoxQ1" runat="server" Width="160"/>
</ItemTemplate>
</telerik:RadCombo开发者_开发知识库Box>
Load textboxes:
private void LoadDropdownListItems()
{
int itemCount = 0;
while (itemCount < 50)
{
ddlListItemsQ1.Items.Add(new RadComboBoxItem());
itemCount++;
}
}
Examine collection:
RadComboBox ddlListItems = (RadComboBox)FindControl("ddlListItemsQ1");
IList<RadComboBoxItem> iList = ddlListItems.Items;
foreach (RadComboBoxItem rcbi in iList)
{
if (rcbi.Text.Length > 0)
return true;
}
Nothing is in any of the textboxes. For example, if I've entered text into 2 of the 50, I should get a "true" returned on the first one it comes across. When I debug and look at the collection - there is nothing stored in ANY of the textboxes even though in the UI, there are two with data. I must be missing something...
Your for loop is checking rcbi.Text
but that is the Text of the RadComboBoxItem
s that you added to the combo box....which is different than the text that is in the TextBox
that you placed as part of the ItemTemplate
. Change your for loop to this and it should work:
IList<RadComboBoxItem> iList = ddlListItems.Items;
foreach (RadComboBoxItem rcbi in iList)
{
//Find the inner textbox placed by the ItemTemplate
var innerTextBox = (TextBox)rcbi.FindControl("txtBoxQ1");
/Check the textbox's Text property
if (innerTextBox.Text.Length > 0)
return true;
}
精彩评论