本文介绍了如何获取动态创建的单选按钮列表的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Masterpage继承的页面中创建了一个动态单选按钮列表,如下所示.

i created a dynamic radiobuttonlist in Masterpage inherited page like this.this is working.

RadioButtonList rbl = new RadioButtonList();
rbl.ID = "rblID";

//Add Items
rbl.Items.Add(new ListItem("One", "1"));
rbl.Items.Add(new ListItem("Two", "2"));
rbl.Items.Add(new ListItem("Three", "3"));

rbl.DataBind();
PlaceHolder1.Controls.Add(rbl);



我需要找到单选按钮列表的选定值.我尝试了以下代码,但无法正常工作.



i need to find the selected value of radiobuttonlist. i tried the below code, but it is not working.

RadioButtonList rb = (RadioButtonList)FindControl("rblID");
TextBox1.Text = rb.SelectedValue;

推荐答案

RadioButtonList rb = (RadioButtonList)Master.FindControl("rblID");
TextBox1.Text = rb.SelectedValue;


RadioButtonList rbl = new RadioButtonList();
rbl.ID = "rblID";
rbl.AutopostBack="true";


rbl.Items.Add(new ListItem("One", "1"));
rbl.Items.Add(new ListItem("Two", "2"));
rbl.Items.Add(new ListItem("Three", "3"));

rbl.DataBind();
PlaceHolder1.Controls.Add(rbl);









RadioButtonList rb = (RadioButtonList)FindControl("rblID");
TextBox1.Text = rb.SelectedValue; 


这篇关于如何获取动态创建的单选按钮列表的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-10 11:07