网格视图和下拉列表
是否可以从同一 gridview 中的另一个下拉列表选择索引更改方法更改 gridview 中下拉列表的数据源?
例如,我有一个下拉列表,需要根据 gridview 的前一个单元格中选择的内容来更改其内容,这也是一个下拉列表。
任何帮助将不胜感激
谢谢
Is it possible to change the data source of a dropdown list in a gridview from another dropdown list selected index changed method in the same gridview?
for example I have a dropdown that needs to change its contents depending on what is chosen in the previous cell of the gridview, which is also a dropdown list.
Any Help would be much appreciated
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当第一个
DropDownList.SelectedIndex
更改时,您可以设置第二个DropDownList
的DataSource
,而不是更改DataSource
当它被编辑时。有关如何实现此目的的示例,请参见此处 。
在本文中,作者挂钩
EditingControlShowing
事件以更改ComboBox
的类型。可以轻松修改此值以更改DataSource
:Instead of changing the
DataSource
when the 1stDropDownList.SelectedIndex
changes, you could set theDataSource
of the 2ndDropDownList
when it is being edited.An example of how this can be achieved can be found here.
In this article, the author hooks to the
EditingControlShowing
event in order to change the type of theComboBox
. This can be easily modified to change theDataSource
instead:这是我执行此操作的另一种方法,例如:两列(类型、天),如果用户下拉并选择“周”,则第二个组合将填充工作日,否则填充周末。
出于本示例的目的,添加一个具有两个 ComboBoxCell 列的网格 (DataGridView1),并让第一列包含以下项目:周、周末。
这个类将是我们的数据源:
这个函数将根据可以是“week”或“weekend”的键返回我们的数据源:
最后,当 Type 组合值更改时将触发此事件,并分配适当的数据我们的天组合的来源:
请注意,此事件在单元格经过验证后触发,即一旦您关闭单元格。
Here is another way how I would do this, by example: Two columns (Types, Days), if the user drops-down and chooses 'week', a second combo populates with week days, otherwise, weekends.
For the purpose of this example, add a grid (DataGridView1) with two ComboBoxCell columns and let the first column have these items: week, weekend.
This class will be our data source:
This function will return our data source, based on the key which can be 'week' or 'weekend':
And lastly, this event will fire when the Type combo value changes, and assign the appropriate data source to our days combo:
Note that this event fires after the cell is validated, ie once you tab off the cell.
这是完全有可能的。如何填充您的下拉列表?如果所有数据都是动态的,那么每次更改下拉列表所选项目时,您都必须重建整个网格。
如果我没记错的话,你正在尝试应用过滤机制。你是 ?我过去做过的另一种方法是从 GridView 的行构建 DropDownList 的数据源。想想屏幕上已有的数据。进入 PreRender Function 后,您可以在下拉列表中绑定所需的数据,这样您就可以减少负载。
It is totally possible. How are populating your dropdownlists ? If all the data is dynamic then you will have to rebuild the entire grid everytime you change the dropdownlist selected item.
If I am not wrong , you are trying to apply Filter mechanism. Are you ? Another way I have done in the past is to build my data source for DropDownList from the rows of GridView. Think about the data that you already have on the screen. Once you are in PreRender Function you can bind needed data in your dropdownlist, this way you will cut out load.