我有一个单选按钮列表,我正在用字符串填充,我想知道如何在给定的时间内获得所选元素的值并将其抛入字符串中。但是使用命令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>
//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";
}
}发布于 2014-01-04 02:20:25
看起来您正在页面加载上填充RadioButtonList -如果是这样的话-确保您使用If/ then /Postback块围绕您的RadioButtonList填充: If not Page.IsPostBack then‘填充您的RBL end if
例如:
if (!IsPostBack)
{
loadradiobuttonlist();
}发布于 2013-08-23 18:49:00
首先,这是一个让你知道价值的页面,而不是应用程序获取价值的页面。
因此,您需要一个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是您的单选按钮列表选择索引。使用它从列表中选择项目。
https://stackoverflow.com/questions/18393060
复制相似问题