由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
DotNet版 - 一个dropdownlist的问题
相关主题
image with RadioButtonList c#mvc pros and cons
listbox 的问题control array in .net
Answer Re: ASP.NET 难题测试 (1)C#的更高境界
ASP.NET 难题测试 (1)LinqPad is handy
怎样用c#.net生成一个动态表格?小菜鸟求助,PDF header signature not found
static or else?菜鸟继续问:how to update sql db entry, or create if not exist ?
[转载] 问一个javascript 和 .NET 的问题请教:是否可以overwrite session variable里面的item.
Ajax Toolkit is troublesome in versions.NET 入门系列(3)--SOAP, WSDL, disco
相关话题的讨论汇总
话题: page话题: listitem话题: 问题话题: item
进入DotNet版参与讨论
1 (共1页)
j****n
发帖数: 107
1
一个dropdownlist,从数据库读取数据动态生成list item.
出现这样一个问题,无论选择了哪一个item,list.SelectedValue永远
等于排在第一的那个item值。
这是可能什么问题造成的?查了一遍又一遍,就是看不出错在哪里了。
哪位牛人来帮我看一下啊?同样的code在其它文件里都跑得好好的。
生成list的code如下:
DropDownList.Items.Clear();
foreach ( ListItem myItem in myListItems)
DropDownList.Items.Add(new ListItem(myItem.Text, myItem.Value));
DropDownList.SelectedIndex = -1;
多谢多谢!
k****i
发帖数: 1072
2
In which event did you put this code?
If it's a webapp,put it in init but not page load

【在 j****n 的大作中提到】
: 一个dropdownlist,从数据库读取数据动态生成list item.
: 出现这样一个问题,无论选择了哪一个item,list.SelectedValue永远
: 等于排在第一的那个item值。
: 这是可能什么问题造成的?查了一遍又一遍,就是看不出错在哪里了。
: 哪位牛人来帮我看一下啊?同样的code在其它文件里都跑得好好的。
: 生成list的code如下:
: DropDownList.Items.Clear();
: foreach ( ListItem myItem in myListItems)
: DropDownList.Items.Add(new ListItem(myItem.Text, myItem.Value));
: DropDownList.SelectedIndex = -1;

j****n
发帖数: 107
3
Thank u for ur reply.
But it is put in an Init_DropDownList event.

【在 k****i 的大作中提到】
: In which event did you put this code?
: If it's a webapp,put it in init but not page load

b********s
发帖数: 12
4
你有没有设置dropdownlist的autopostback 为true?

【在 j****n 的大作中提到】
: Thank u for ur reply.
: But it is put in an Init_DropDownList event.

k****i
发帖数: 1072
5
I would suggest you to move it to Page OnInit() and get rid of the line
'DropDownList.SelectedIndex = -1'(actually this line have no effect on
dropdownlist)

【在 j****n 的大作中提到】
: Thank u for ur reply.
: But it is put in an Init_DropDownList event.

j****n
发帖数: 107
6
设置了,但是没有任何作用。

【在 b********s 的大作中提到】
: 你有没有设置dropdownlist的autopostback 为true?
j****n
发帖数: 107
7
Thanks, I'll try it tomorrow.

【在 k****i 的大作中提到】
: I would suggest you to move it to Page OnInit() and get rid of the line
: 'DropDownList.SelectedIndex = -1'(actually this line have no effect on
: dropdownlist)

G**T
发帖数: 388
8

I would suggest bind data to the dropdownlist in pageload
I did this in my application, never had this problem
seems somthhing is wrong at other places
I would

【在 j****n 的大作中提到】
: Thanks, I'll try it tomorrow.
k****i
发帖数: 1072
9
R u sure?
data binding in pageload will overwrite the value retrieve from viewstate and
would cause the problem that julyan encountered.Unless you use !IsPostBack

【在 G**T 的大作中提到】
:
: I would suggest bind data to the dropdownlist in pageload
: I did this in my application, never had this problem
: seems somthhing is wrong at other places
: I would

G**T
发帖数: 388
10

and
ur right, use NOT isPostBack
line

【在 k****i 的大作中提到】
: R u sure?
: data binding in pageload will overwrite the value retrieve from viewstate and
: would cause the problem that julyan encountered.Unless you use !IsPostBack

M******k
发帖数: 27573
11
en, i guess your solution is correct.
the re-initialize of dropdownlist in Page_Load
overwrite the viewstate, so he can't get selectedValue
in the event.

【在 k****i 的大作中提到】
: R u sure?
: data binding in pageload will overwrite the value retrieve from viewstate and
: would cause the problem that julyan encountered.Unless you use !IsPostBack

1 (共1页)
进入DotNet版参与讨论
相关主题
.NET 入门系列(3)--SOAP, WSDL, disco怎样用c#.net生成一个动态表格?
[转载] C# 中comboBox DataBinding 问题static or else?
[转载] a socket Question[转载] 问一个javascript 和 .NET 的问题
怎样用csharp读取某个web页面指定表格的内容?Ajax Toolkit is troublesome in versions
image with RadioButtonList c#mvc pros and cons
listbox 的问题control array in .net
Answer Re: ASP.NET 难题测试 (1)C#的更高境界
ASP.NET 难题测试 (1)LinqPad is handy
相关话题的讨论汇总
话题: page话题: listitem话题: 问题话题: item