维护DropDownList选择的索引 [英] Maintaining DropDownList selected index
问题描述
提前致谢!我想在回发时维护一个dl列表的选定索引
。我正在做的是当一个人从
下拉列表中选择一个项目时,我在日历控件中选择一个日期并用日期填充一个
文本框。为此,我将自动回发设置为下拉列表
。但它总是在帖子后面重置选定的索引。我在onLoad方法中对此进行
控制......
如果不是Page.IsPostBack那么
如果页面回发我选择日期并正确填充textbox.text
。选定的索引丢失。我甚至用选定的索引在
视图状态中添加了一个键,并尝试从
中获取值,但仍然没有。请帮助!
Thanks in advance! I''m trying to maintain a dl list''s selected index
on postback. What I''m doing is when a person selects an item from the
drop down list I select a date in a calendar control and populate a
text box with the date. To do this I set auto postback to the drop
down list. But it always resets the selected index on post back. I
control for this in the onLoad method...
If Not Page.IsPostBack Then
If page is posted back I select the date and populate textbox.text
correctly. Selected index is lost. I even added a key to the
viewstate with the selected index and tried grabbing the value from
that, but still no go. Help please!
推荐答案
下拉列表通常会保持其视图状态,除非您重新绑定它们
他们的数据源。但是我发现如果你的DDL绑定了一个
DataSourceControl,并且你的DDL在另一个控件内(比如在DetailsView的
模板字段中),那么如果你做一些事情,比如更新
detailsview控件中某个字段的headerText,那么它就会重新设置父控件中所有子控件的视图状态。
" Phuff"写道:
Drop down lists do usually maintain their viewstate unless you re-bind them
to their datasource. Howeve i have found that if your DDL is bound to a
DataSourceControl, and your DDL is within another control (such as in a
template field of a DetailsView), then if you do something such as updatting
the headerText of one of the Fields in the detailsview control then it
re-sets the view state of all child controls within parent control.
"Phuff" wrote:
提前致谢!我正在尝试在回发时维护一个dl列表的选定索引
。我正在做的是当一个人从
下拉列表中选择一个项目时,我在日历控件中选择一个日期并用日期填充一个
文本框。为此,我将自动回发设置为下拉列表。但它总是在帖子后面重置选定的索引。我在onLoad方法中对此进行控制...
如果不是Page.IsPostBack那么
如果页面被回发,我选择日期并填充文本框。文字
正确。选定的索引丢失。我甚至用选定的索引向
viewstate添加了一个键,并尝试从
获取值,但仍然没有去。请帮助!
Thanks in advance! I''m trying to maintain a dl list''s selected index
on postback. What I''m doing is when a person selects an item from the
drop down list I select a date in a calendar control and populate a
text box with the date. To do this I set auto postback to the drop
down list. But it always resets the selected index on post back. I
control for this in the onLoad method...
If Not Page.IsPostBack Then
If page is posted back I select the date and populate textbox.text
correctly. Selected index is lost. I even added a key to the
viewstate with the selected index and tried grabbing the value from
that, but still no go. Help please!
谢谢,但不受约束。我所做的是从SQL查询中获取数据集来获取
,然后执行Items.add方法。
我实际上发现它会维护2个选定的州。一个
标记为7和1.第一个索引是描述所有项目的文本字段。
然后我添加其他字段作为数字。该值也设置为
等于字段中作为字符串列出的数字。在我的测试中
例子我有一个字符串......Box / Unit ID然后是1-8的项目。如果我
选择7它将实际保留此索引。其他一切都默认为
1.
Thanks, but its not bound. What I do is loop through dataset grabbed
from a sql query, and then do an Items.add method.
I have actually found that it will maintain 2 selected states. One
labeled 7 and 1. The first index is a text field describing all items.
Then I add the other fields which are numbers. The value is also set
to equal the number listed as a string in the field. OIn my test
example I have a string..."Box/Unit ID" and then an item for 1-8. If I
select 7 it will actually keep this index. Everything else defaults to
1.
为什么不绑定它,然后它会维护ViewState?
" Phuff"写道:
Why not just bind it instead, then it will maintain ViewState?
"Phuff" wrote:
谢谢,但它没有约束。我所做的是从SQL查询中获取数据集,然后执行Items.add方法。
我实际上发现它将保持2个选定的状态。一个标记为7和1的第一个索引是描述所有项目的文本字段。
然后我添加其他字段,这些字段是数字。该值也设置为等于字段中作为字符串列出的数字。在我的测试中
示例我有一个字符串...Box / Unit ID然后是1-8的项目。如果我选择7,它实际上会保留这个索引。其他一切都默认为
1.
Thanks, but its not bound. What I do is loop through dataset grabbed
from a sql query, and then do an Items.add method.
I have actually found that it will maintain 2 selected states. One
labeled 7 and 1. The first index is a text field describing all items.
Then I add the other fields which are numbers. The value is also set
to equal the number listed as a string in the field. OIn my test
example I have a string..."Box/Unit ID" and then an item for 1-8. If I
select 7 it will actually keep this index. Everything else defaults to
1.
这篇关于维护DropDownList选择的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!