简体   繁体   English

DropDownList Asp.net的怪异行为

[英]Weird behaviour of DropDownList Asp.net

Weird behaviour happening in my DropDownList Asp.net 我的DropDownList Asp.net中发生的奇怪行为

My Code: 我的代码:

                 <asp:DropDownList ID="DDLFromMinutes" runat="server" Width="20%">
                                <asp:ListItem Text="00" Value="00"></asp:ListItem>
                                <asp:ListItem Text="15" Value="15"></asp:ListItem>
                                <asp:ListItem Text="30" Value="30"></asp:ListItem>
                                <asp:ListItem Text="45" Value="45"></asp:ListItem>
                            </asp:DropDownList>

However when i run it for example if 15 is the Selected Value i get it Twice in my DropDownList 但是,当我运行它时,例如,如果15是Selected Value,我在DropDownList得到两次

While Debugging in FireBug get the following: 在FireBug中进行调试时,请获取以下信息:

<select id="ContentPlaceHolder1_DDLFromMinutes" style="width:20%;" name="ctl00$ContentPlaceHolder1$DDLFromMinutes">
<option value="00" selected="selected">30</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
</select>

Code behind: 后面的代码:

string Frominput = seprateFromTime[1];
                string Frommin = Frominput.Substring(0, 2);
                DDLFromMinutes.SelectedItem.Text = Frommin;
                if (DDLFromMinutes.Items.Count > 0)
                {
                    DDLFromMinutes.SelectedIndex = DDLFromMinutes.Items.IndexOf(DDLFromMinutes.Items.FindByText(Frommin));
                }

在此处输入图片说明

While saving the Data is use DDLFromMinutes.SelectedItem.Text Could this be an issue? 保存数据时使用DDLFromMinutes.SelectedItem.Text这可能是一个问题吗?

You need to use MyDropDown.SelectedValue instead of selectedItem.Text. 您需要使用MyDropDown.SelectedValue而不是selectedItem.Text。

Details here: MSDN 详细信息在这里: MSDN

do you want to get the value of drop down list? 您想获得下拉列表的价值吗? If so, I think you need to change SelectedItem to SeletedValue. 如果是这样,我认为您需要将SelectedItem更改为SeletedValue。

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

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