1
上午具有基于数据的下拉列表,默认选择由用户会话设置。它工作正常,但如果我尝试在列表中选择不同的项目后,它将跳回到默认值。我使用的Visual Studio 2015年,Web表单,asp.net无法在DDL获得deafult值后更改选择
我尝试在2路,目前仍是同样的问题
if (Session["plyer2"] != null) {
string DropDownListSelected = Session["plyer1"].ToString();
DropDownList1.ClearSelection();
DropDownList1.Items.FindByValue(DropDownListSelected).Selected = true;
DropDownList2.SelectedValue = Session["plyer2"].ToString(); }
已经在过去的2当天没有找到帮助谷歌搜索选择默认项
的DDL是自动回发
的代码是在.aspx.cs文件:protected void Page_Load(object sender, EventArgs e)
的数据绑定是在.aspx文件
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource5" DataTextField="forshow" DataValueField="forshow" AppendDataBoundItems="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="1">בחר גארד</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [forshow] FROM [players] WHERE ([position] = @position)">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="גארד" Name="position" QueryStringField="גארד" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
这段代码位于何处(在哪个方法中)以及你在哪里绑定下拉列表? – M4N
代码位于.aspx.cs文件中: protected void Page_Load(object sender,EventArgs e) databind位于.aspx文件中 –