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 コードビハインド 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 に答える