Dropdownlist始终返回'0'索引的值。 [英] Dropdownlist always return value of '0' index.
本文介绍了Dropdownlist始终返回'0'索引的值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的下拉列表总是返回第一个索引的值,无论选择哪个值。我没有在页面加载上填充数据已经在列表项中提供了值。
并且没有给出selectitemvalues无论如何
我的代码是。
< pre> < asp:DropDownList ID = DropDownlistPriceSegmentC runat = server BackColor = #EBEAD2 高度= 40px宽度= 100% EnableViewState = true >
< asp:ListItem Value = 0> 200 < / asp:ListItem >
< asp:ListItem Value = 0> 225 < / asp:ListItem >
< asp:ListItem Value = 0> 250 < / asp:ListItem >
< asp:ListItem Value = 0> 275 < / asp:ListItem >
< asp:ListItem Value = 0> 300 < / asp:ListItem >
< asp:ListItem Value = 5> 325 < / asp:ListItem >
< ; asp:ListItem Value = 0> 350 < / asp:ListItem >
< asp:ListItem Value = 0> 375 < / / span> asp:ListItem >
< asp:ListItem Value = 0 > 400 < / asp:ListItem >
< / asp:DropDownList >
我尝试了什么:
我启用了下拉列表的视图状态。
解决方案
值
所有项目的属性(例如325)设置为0
,所以我对这个值并不感到惊讶你得到的总是0
。将任何项目的Value
属性设置为唯一且可识别的属性。
啊,所以索引总是0,而不是值?
我还是会尝试更改值属性。 ASP.NET可能会根据请求中发布的Value
派生索引(因此,ASP.NET看到值为零,执行索引,并发现第一个dropdownlist元素的值为零,因此索引为零)。如果是这种情况(我认为是这样,因为Web浏览器在请求中发送选定的值,而不是选定的索引),唯一值
s将导致正确的索引
My dropdownlist always return me the value of first index no matter which value is selected.I'm not populating data on page load is have provided values in list-item .
and not giving the selecteditemvalues anyways
MY Code is.
<pre> <asp:DropDownList ID="DropDownlistPriceSegmentC" runat="server" BackColor="#EBEAD2" Height="40px" Width="100%" EnableViewState="true">
<asp:ListItem Value="0">200</asp:ListItem>
<asp:ListItem Value="0">225</asp:ListItem>
<asp:ListItem Value="0">250</asp:ListItem>
<asp:ListItem Value="0">275</asp:ListItem>
<asp:ListItem Value="0">300</asp:ListItem>
<asp:ListItem Value="5">325</asp:ListItem>
<asp:ListItem Value="0">350</asp:ListItem>
<asp:ListItem Value="0">375</asp:ListItem>
<asp:ListItem Value="0">400</asp:ListItem>
</asp:DropDownList>
What I have tried:
I have enable the view state of the dropdownlist.
解决方案
TheValue
attribute of all items (exxcept 325) is set to"0"
, so I'm not surprised that the value you get is always0
. Set theValue
attribute for any item to something unique and identifiable.
[Edit]
Ah, so the index is always 0, not the value?
I would still try to change the 'Value' attributes. It's likely that ASP.NET derives the index based on theValue
posted in the request (so, ASP.NET sees a Value of zero, performs indexing, and finds out that the first dropdownlist element has value zero, so the index is zero). If that's the case (and I think it is, because web browsers send the selected Value in a request, not the selected index), uniqueValue
s will lead to a correct index.
这篇关于Dropdownlist始终返回'0'索引的值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文