Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# RadioButtonList空值_C#_Asp.net_Radiobuttonlist - Fatal编程技术网

C# RadioButtonList空值

C# RadioButtonList空值,c#,asp.net,radiobuttonlist,C#,Asp.net,Radiobuttonlist,有一个单选按钮列表,我用字符串填充它,我想知道如何在给定的时间内获取所选元素的值,并将其放入字符串中。但是使用SelectedValue和SelectedItem命令时,只有空值​​. 此单选按钮列表在执行同一页面时会填写多次 //Where do you fill the RadioButtonList public void MostraImagensCarrefadas() { List<String> files = new manFile().getListFile

有一个单选按钮列表,我用字符串填充它,我想知道如何在给定的时间内获取所选元素的值,并将其放入字符串中。但是使用SelectedValue和SelectedItem命令时,只有空值​​.

此单选按钮列表在执行同一页面时会填写多次

//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>

首先,这是让您知道值的页面,而不是应用程序得到它的页面

因此,您需要一个脚本管理器和计时器,它们都是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
是您的RadioButton列表选择索引。使用它从列表中选择项目

您似乎正在页面加载中填充RadioButton列表- 如果是这样的话,请确保在RadioButtonList的用户周围放置一个 If/Then/Postback块: 如果不是Page.IsPostBack,则 '填充您的RBL 如果结束

例如:

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;
}
        if (!IsPostBack)
        {
            loadradiobuttonlist();
        }