2012-12-04 33 views
0

在選擇任何觸發後備我的單選按鈕列表選擇goto Index 0的單選按鈕或表單事件時,其他表單項目均不受影響。我禁用了主列表重定向代碼,除了下拉列表,單選按鈕列表和標籤以外,我還創建了一個全新的頁面,其中沒有任何內容可以查看選定的數據。我很難過。RadiobuttonList回傳到索引0

有沒有建議嗎?我只是希望它保持selectedindex,並允許我填寫post backs之間的正確值。

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="s_Default" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder_menuBar" Runat="Server"> 
</asp:Content> 
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder_userBar" Runat="Server"> 
</asp:Content> 
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder_mainActivityWindow" Runat="Server"> 
<form id="Form1" runat="server"> 
    <p> 
     <asp:DropDownList ID="ddl_Shift1" runat="server" AutoPostBack="true" EnableViewState="true"> 
      <asp:ListItem Text="d" Value="d" Selected="True"></asp:ListItem> 
      <asp:ListItem Text="n" Value="n" Selected="False"></asp:ListItem> 
      <asp:ListItem Text="h" Value="h" Selected="False"></asp:ListItem> 
     </asp:DropDownList> 
    </p> 
    <p> 
     <asp:RadioButtonList ID="rbl_C112" runat="server" AutoPostBack="true" EnableViewState="true"> 
      <asp:ListItem Text="2" Value="112" Selected="False" ></asp:ListItem> 
      <asp:ListItem Text="3" Value="112" Selected="False" ></asp:ListItem> 
      <asp:ListItem Text="4" Value="112" Selected="False" ></asp:ListItem> 
      <asp:ListItem Text="5" Value="112" Selected="False" ></asp:ListItem> 
      <asp:ListItem Text="Unassigned" Value="112" Selected="True" ></asp:ListItem> 
     </asp:RadioButtonList> 
    </p>  
    <p> 
     <asp:Label ID="l_c112" Text="" runat="server"></asp:Label> 
     <asp:Label ID="username" Text="" runat="server"></asp:Label> 
    </p> 
    </form> 
</asp:Content> 
<asp:Content ID="Content5" ContentPlaceHolderID="ContentPlaceHolder_tutorialBar" Runat="Server"> 
</asp:Content> 
<asp:Content ID="Content6" ContentPlaceHolderID="ContentPlaceHolder_foot" Runat="Server"> 
</asp:Content> 

VB代碼隱藏s_默認

Partial Class s_Default 
    Inherits System.Web.UI.Page 

    Sub Page_Load() Handles Me.Load 
     username.Text = Session("UserRole").ToString() 
    End Sub 

    Protected Sub rbl_C112_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbl_C112.SelectedIndexChanged 
     l_c112.Text = "" 
     l_c112.Text = rbl_C112.SelectedItem.ToString() 
    End Sub 
End Class 

回答

2

這不是這回後,其所選的值後返回的選擇指標。

由於rbl_C112都具有相同的值(112),它將選擇與該值匹配的第一個值。

更改您的DropDownList選項的值,使它們是唯一的,這將解決您的問題。

<asp:RadioButtonList ID="rbl_C112" runat="server" AutoPostBack="true" EnableViewState="true"> 
     <asp:ListItem Text="2" Value="112" Selected="False" ></asp:ListItem> 
     <asp:ListItem Text="3" Value="113" Selected="False" ></asp:ListItem> 
     <asp:ListItem Text="4" Value="114" Selected="False" ></asp:ListItem> 
     <asp:ListItem Text="5" Value="115" Selected="False" ></asp:ListItem> 
     <asp:ListItem Text="Unassigned" Value="116" Selected="True" ></asp:ListItem> 
</asp:RadioButtonList> 
+0

好的,我看到我的錯誤。我會盡快嘗試。謝謝! – new2asp

1

這是由於幾個具有完全相同的值的列表項的,在回發它使用選擇值來設定的項目,如果你有:

<asp:ListItem Text="2" Value="112" Selected="False" ></asp:ListItem> 
      <asp:ListItem Text="3" Value="112" Selected="False" ></asp:ListItem> 
      <asp:ListItem Text="4" Value="112" Selected="False" ></asp:ListItem> 
      <asp:ListItem Text="5" Value="112" Selected="False" ></asp:ListItem> 
      <asp:ListItem Text="Unassigned" Value="112" Selected="True" ></asp:ListItem> 

然後,如果你選擇5,然後回發它將設置2,因爲這是您選擇的值列表中的第一個項目。