RadComboBox 与 asp:TextBox ItemTemplate 的问题
我正在使用带有 ItemTemplate 的 RadComboBox,其中包含 50 个用户可以在其中输入信息的 TextBox 控件。我动态添加 50 个 TextBox 控件(见下文)。当信息输入到文本框中时,一切似乎都按预期进行。但是,当我迭代 TextBoxes 集合时,数据不存在。这是我的代码:
aspx 页面:
<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:RadComboBox>
加载文本框:
private void LoadDropdownListItems()
{
int itemCount = 0;
while (itemCount < 50)
{
ddlListItemsQ1.Items.Add(new RadComboBoxItem());
itemCount++;
}
}
检查集合:
RadComboBox ddlListItems = (RadComboBox)FindControl("ddlListItemsQ1");
IList<RadComboBoxItem> iList = ddlListItems.Items;
foreach (RadComboBoxItem rcbi in iList)
{
if (rcbi.Text.Length > 0)
return true;
}
任何文本框中都没有任何内容。例如,如果我在 50 个文本中的 2 个中输入了文本,那么我应该在遇到的第一个文本中返回“true”。当我调试并查看集合时 - 任何文本框中都没有存储任何内容,即使在 UI 中,有两个文本框包含数据。我一定是错过了什么……
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:RadComboBox>
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 for 循环正在检查 rcbi.Text,但这是您添加到组合框的 RadComboBoxItem 的文本......这与以下文本不同在作为
ItemTemplate
一部分放置的TextBox
中。将您的 for 循环更改为此,它应该可以工作:Your for loop is checking
rcbi.Text
but that is the Text of theRadComboBoxItem
s that you added to the combo box....which is different than the text that is in theTextBox
that you placed as part of theItemTemplate
. Change your for loop to this and it should work: