首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RadioButtonList空值

RadioButtonList空值
EN

Stack Overflow用户
提问于 2013-08-23 08:55:10
回答 2查看 1.7K关注 0票数 0

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

此单选按钮列表在同一页面的执行过程中会被多次填充。

代码语言:javascript
复制
//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>

代码语言:javascript
复制
 //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";

                    }
                }
EN

回答 2

Stack Overflow用户

发布于 2014-01-04 02:20:25

看起来您正在页面加载上填充RadioButtonList -如果是这样的话-确保您使用If/ then /Postback块围绕您的RadioButtonList填充: If not Page.IsPostBack then‘填充您的RBL end if

例如:

代码语言:javascript
复制
        if (!IsPostBack)
        {
            loadradiobuttonlist();
        }
票数 1
EN

Stack Overflow用户

发布于 2013-08-23 18:49:00

首先,这是一个让你知道价值的页面,而不是应用程序获取价值的页面。

因此,您需要一个ScriptManager和Timer,它们都是Ajax扩展。将它们添加到页面。

代码语言:javascript
复制
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是您的单选按钮列表选择索引。使用它从列表中选择项目。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18393060

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档