0

在选择触发回发的任何单选按钮或表单事件时,我的单选按钮列表选择转到索引 0。其他表单项均不受影响。我禁用了主列表重定向代码,我创建了一个全新的页面,其中除了下拉列表、单选按钮列表和用于查看所选数据的标签之外什么都没有。我难住了。

有什么建议吗?我只希望它保留 selectedindex 并允许我在回发之间填充正确的值。

    <%@ 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 Codebehind s_Default

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
4

2 回答 2

4

回发后返回的不是选定的索引,而是选定的值。

由于rbl_C112都具有相同的值 ( 112),因此它将选择与该值匹配的第一个 1。

更改 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>
于 2012-12-04T09:17:47.763 回答
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,因为这是列表中具有您选择的值的第一项。

于 2012-12-04T09:18:06.510 回答