2016-11-15 35 views
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> 
+0

這段代碼位於何處(在哪個方法中)以及你在哪裏綁定下拉列表? – M4N

+0

代碼位於.aspx.cs文件中: protected void Page_Load(object sender,EventArgs e) databind位於.aspx文件中 –

回答

0

以及它沒有真正的答案的問題,但由於我使用會話來選擇項目,我添加

  Session.Abandon(); 

所以其取消IF語句的下一個頁面加載這是夠好對我來說