简体   繁体   English

某个地方有文本框列表控件吗?

[英]Is there a textboxlist control available somewhere?

There are ASP controls such as radiobuttonlist and checkboxlist and you can databind them to a database query. 有ASP控件,例如单选按钮列表和复选框列表,您可以将它们数据绑定到数据库查询。 It's great for creating dynamic lists with user interaction. 通过用户交互创建动态列表非常有用。 What I'm trying to do is generate a list of textboxes in the same fashion. 我正在尝试以相同的方式生成文本框列表。 A list of textboxes that behave the same way. 行为相同的文本框列表。

The object is to have a checkboxlist that is generated via datasource/database. 该对象将具有一个通过数据源/数据库生成的复选框列表。 When the user is finished selecting items from this list, they click a button. 当用户完成从该列表中选择项目时,他们单击一个按钮。 That list hides (using jquery) and a new list is created based on their selections. 该列表隐藏(使用jquery),并根据其选择创建一个新列表。 However, the new list is now a list of their selections accompanied by an empty textbox. 但是,新列表现在是其选择的列表,并附带一个空的文本框。 The user fills in the textboxes for each entry and submits again which commits it to a database. 用户填写每个条目的文本框,然后再次提交,将其提交到数据库。

SO: 所以:

checkbox - description
checkbox - description
checkbox - description
checkbox - description

Becomes: 成为:

Description - Textbox
Description - Textbox

The reason that I'm looking for a list-type control is so that I can ultimately loop through it for submission to the database using linq. 我正在寻找列表类型控件的原因是,我最终可以遍历它以使用linq提交给数据库。 Does that make sense? 那有意义吗? My real question is if there is a control like this yet. 我真正的问题是是否存在这样的控件。 I gave the full description in case someone has any other ideas, short of creating a custom control. 我提供了完整的描述,以防万一有人有其他想法,而没有创建自定义控件。

There's nothing out of the box that does what you describe no. 没有什么开箱即用的功能可以满足您的要求。 But you can still loop through controls. 但是您仍然可以循环浏览控件。 I would put your form controls inside of an asp:Panel or a div with runat="server" and use something like the following code to cycle through them as you described. 我会将您的表单控件放在带有runat =“ server”的asp:Panel或div内,然后使用类似以下代码的代码循环遍历它们。

foreach(Control ctl in myPanel.Controls)
{
  //check control type and handle
  if (ctl is TextBox)
  {
     //handle the control and its value here
  }
}

asp:ListBox has a property named SelectionMode, which can be set to SelectionMode="Multiple" and allows you to select items you want. asp:ListBox具有一个名为SelectionMode的属性,可以将其设置为SelectionMode =“ Multiple”,并允许您选择所需的项目。 This is not exactly what you need but it's a simple solution. 这并不是您真正需要的,但这是一个简单的解决方案。

After the selection is made in checkboxlist, make a postback to server. 在复选框列表中选择之后,将回发到服务器。 Here create a datatable with two columns (description & text). 在这里创建一个具有两列(描述和文本)的数据表。 For every selected item in the checkboxlist add a row to this table and bind it to a gridview control. 对于复选框列表中的每个选定项目,在此表中添加一行并将其绑定到gridview控件。 Here 'text' column will be always empty. 此处的“文本”列将始终为空。 Configure the gridview to use template column with a textbox in the itemtemplate 配置gridview以将template列与itemtemplate中的文本框一起使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM