本文介绍了DropDownList 所选项目始终是列表中的第一项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在用户控件中有一个 DropDownList;但是,无论我做什么,我都无法正确填充任何选定"属性(SelectedItem、SelectedIndex、SelectedValue).无论实际选择了哪一项,这三个属性的值都是我列表中的第一项.
I have a DropDownList in a user control; however, no matter what I do I can't get any of the "selected" properties (SelectedItem, SelectedIndex, SelectedValue) to populate correctly. The value of all three of these properties is the first item in my list no matter which item was actually selected.
<asp:DropDownList ID="ParticipantsSelectList" runat="server">
<asp:ListItem Value="">Please select a team...</asp:ListItem>
<asp:ListItem value="{D37EFA0C-988A-4A2A-8D6E-80E3BAE00DEE}">Blue Team</asp:ListItem>
<asp:ListItem value="{7543E282-C9B8-435A-86A2-70E8E3BB38E5}">Green Team</asp:ListItem>
<asp:ListItem value="{F6BEF34A-215E-4179-9F4C-68F7C43D755F}">Orange Team</asp:ListItem>
<asp:ListItem value="{D50AD44A-686A-4BD3-B62E-D70ABF153AE5}">Red Team</asp:ListItem>
<asp:ListItem value="{DEFB7DA6-B0FF-4C36-A015-F3E8BC7AECA2}">Yellow Team</asp:ListItem>
<asp:ListItem value="{D37EFA0C-988A-4A2A-8D6E-80E3BAE00DEE},{7543E282-C9B8-435A-86A2-70E8E3BB38E5},{F6BEF34A-215E-4179-9F4C-68F7C43D755F},{D50AD44A-686A-4BD3-B62E-D70ABF153AE5},{DEFB7DA6-B0FF-4C36-A015-F3E8BC7AECA2}">All Teams</asp:ListItem>
</asp:DropDownList>
<asp:Button runat="server" Text="Submit" />
<小时>
private void Page_Load(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(ParticipantsSelectList.SelectedValue)) // SelectedValue is always empty string (value of the first item in the list)
{
resultsPanel.Visible = true;
selectTeamLabel.Visible = false;
GenerateResultsTable();
}
else
{
resultsPanel.Visible = false;
selectTeamLabel.Visible = true;
}
}
推荐答案
尝试在 Page_Load
private void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//Your Code....
}
}
这篇关于DropDownList 所选项目始终是列表中的第一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!