0

私が文字列で埋めているラジオボタンリストがあり、特定の時間に選択した要素の値を取得して、たとえば文字列にスローする方法を知りたいです。ただし、コマンド SelectedValue と SelectedItem では、null 値しかありません 。

このラジオ ボタン リストは、同じページの実行中に数回入力されます。

//Where do you fill the RadioButtonList
public void MostraImagensCarrefadas()
{
    List<String> files = new manFile().getListFilesForDirectory(this, MAE.DIRETORIO_TEMP_IMG);

    rbImagemPrincipal.Items.Clear();

    if (files != null)
    {
        foreach (String item in files)
        {
            rbImagemPrincipal.Items.Add(new ListItem(item));
        }
    }
}


//As it is in aspx
<div>
<asp:RadioButtonList ID="rbImagemPrincipal" runat="server" RepeatDirection="Vertical" AutoPostBack="false" OnSelectedIndexChanged="rbImagemPrincipal_SelectedIndexChanged"></asp:RadioButtonList>

 //where only encounter null values ​​when trying to get the selected item (clicked)
 //Nothing I do is the value obtained direferente null.
if (rbImagemPrincipal.SelectedItem != null)
                {
                    if (rbImagemPrincipal.SelectedItem.ToString() == str)
                    {
                        imagem.imagemPrincipal = "SIM";

                    }
                }
4

2 に答える 2

1

ページの読み込み時に RadioButtonList に値を設定しているようです - その場合は、RadioButtonList の値を If/Then/Postback ブロックで囲んでください: if not Page.IsPostBack then ' RBL end if

例えば:

        if (!IsPostBack)
        {
            loadradiobuttonlist();
        }
于 2014-01-03T18:20:25.327 に答える
0

まず第一に、これはアプリケーションが値を取得するのではなく、値を知らせるページです。

そのため、ScriptManager と Timer が必要です。どちらも Ajax 拡張機能です。それらをページに追加します。

protected void Page_Load(object sender, EventArgs e)
{
    Timer1.Interval = 2000; // set your interval
}
protected void Timer1_Tick(object sender, EventArgs e)
{
     int result =  RadioButtonList1.SelectedIndex;
}

resultラジオボタンリストの選択インデックスです。リストからアイテムを選択するために使用します。

于 2013-08-23T10:49:00.480 に答える