vini
vini

Reputation: 4740

Weird behaviour of DropDownList Asp.net

Weird behaviour happening in my 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

While Debugging in FireBug get the following:

<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));
                }

enter image description here

While saving the Data is use DDLFromMinutes.SelectedItem.Text Could this be an issue?

Upvotes: 0

Views: 203

Answers (2)

mrqyue
mrqyue

Reputation: 94

do you want to get the value of drop down list? If so, I think you need to change SelectedItem to SeletedValue.

Upvotes: 0

Brian Webster
Brian Webster

Reputation: 30875

You need to use MyDropDown.SelectedValue instead of selectedItem.Text.

Details here: MSDN

Upvotes: 1

Related Questions