1

次のコードを使用すると、次のエラーが返されます: 'rblPermisSejourA' には、アイテムのリストに存在しないため無効な SelectedValue があります。

<asp:RadioButtonList ID="rblPermisSejour" runat="server"
DataSourceID="EntityDataSourcePermisSejour" DataTextField="Libelle"
DataValueField="Id" AppendDataBoundItems="True" RepeatDirection="Horizontal">
<asp:ListItem Selected="True" Text="" Value="-1">Aucun</asp:ListItem>
</asp:RadioButtonList>

<asp:RadioButtonList ID="rblPermisSejourA" runat="server"
DataSourceID="EntityDataSourcePermisSejour" DataTextField="Libelle"
DataValueField="Id" AppendDataBoundItems="True" RepeatDirection="Horizontal">
<asp:ListItem Selected="True" Text="" Value="-1">Aucun</asp:ListItem>
</asp:RadioButtonList>

protected void ws2_OnDeactivate(object sender, EventArgs e)
{
  rblPermisSejourA.SelectedValue = rblPermisSejour.SelectedValue;
}

「rblPermisSejour」はウィザード ステップにあり、「rblPermisSejourA」はまだアクティブ化されていない別のウィザード ステップにあることに注意してください (「rblPermisSejourA」があるステップの ID もタイトルもありません)。このステップがアクティブになると、すべてがうまく機能しています。
しかし、別の RadioButtonList で同じコードと同じ操作を使用すると、同じコンテキスト内で非常にうまく機能します(ウィザードのステップはアクティブ化されません)。

4

3 に答える 3

0

やってみました

rblPermisSejourA.SelectedValue = rblPermisSejour.SelectedItem.Value;
于 2012-11-25T05:50:55.040 に答える
0

コメントより

<asp:ListItem Selected="True" Value="1">A</asp:ListItem>
<asp:ListItem Selected="True" Value="2">C</asp:ListItem>

両方のアイテムが selected="true" であるため、 .SelectedValue を呼び出すと、意味する値がわからないため、問題が発生する可能性があります。これらは rblPermisSejourA または rblPermisSejour からのリスト項目ですか? 質問を編集して両方のリストを追加すると、この行が何であるかがわかります

rblPermisSejourA.SelectedValue = rblPermisSejour.SelectedValue;

あなたのエラーを実行して把握しようとしています。

編集

次のようなことを試しましたか

rblPermisSejourA.Items.FindByValue(rblPermisSejour.SelectedValue).Selected = true;
于 2012-11-23T14:34:58.493 に答える
0

これが解決策です:

if (rblPermisSejourA.Items.Count <= 1)
    rblPermisSejourA.DataBind(); //バグを修正するために追加
rblPermisSejourA.SelectedValue = rblPermisSejour.SelectedValue;

于 2012-11-28T12:23:04.377 に答える