RadioButtonList在DataList或者GridView里什么取值 本人自学所以基础很差- -~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先在gridview中findcontrol(),找到这个RadioButtonList控件,然后强制转换成RadioButtonList。就跟一般的RadioButtonList一样的用了。 额你有没有绑定DataList的- -~~ Refer:http://www.cnblogs.com/insus/archive/2013/05/07/3064844.html View Code private List<Survey> SurveyData() { List<Survey> s = new List<Survey>(); s.Add(new Survey("1.1", "title 1")); s.Add(new Survey("1.2", "title 1")); s.Add(new Survey("1.3", "title 1")); return s; }这里是放在类里还是放在~新建的aspx里?- -刚刚入门问的问题有点内阁个~但是还是希望你能教教 protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn("name",typeof(string)), new DataColumn("age",typeof(string)) }); DataRow dr = null; dr = dt.NewRow(); dr["name"] = "guwei"; dr["age"] = "30"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["name"] = "google"; dr["age"] = "28"; dt.Rows.Add(dr); this.DataList1.DataSource = dt; this.DataList1.DataBind(); } } protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { RadioButtonList radioButtonList = e.Item.FindControl("RadioButtonList1") as RadioButtonList; } protected void Button1_Click(object sender, EventArgs e) { foreach (DataListItem item in DataList1.Items) { RadioButtonList radioButtonList = item.FindControl("RadioButtonList1") as RadioButtonList; string value = radioButtonList.SelectedValue; } }<body> <form id="form1" runat="server"> <div> <asp:DataList ID="DataList1" runat="server" onitemdatabound="DataList1_ItemDataBound"> <ItemTemplate> <asp:RadioButtonList ID="RadioButtonList1" runat="server"> <asp:ListItem Text="1" Value="1" /> <asp:ListItem Text="2" Value="2" /> <asp:ListItem Text="3" Value="3" /> </asp:RadioButtonList> </ItemTemplate> </asp:DataList> </div> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </form></body> RadioButtonList rbl=(RadioButtonList)你的数据控件名称.rows[行号].findcontrol("你的radiolist名称")这样就获取到某一行的单选按钮了。获取这里面的值也是很简单的跟普通的一样方式 页面应该看得懂吧,后台注释如下:protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //初始化一个Datatable DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn("name",typeof(string)), new DataColumn("age",typeof(string)) }); DataRow dr = null; dr = dt.NewRow(); dr["name"] = "guwei"; dr["age"] = "30"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["name"] = "google"; dr["age"] = "28"; dt.Rows.Add(dr); //DataList绑定这个Datatable this.DataList1.DataSource = dt; this.DataList1.DataBind(); } } //这个而是DataList1控件的ItemDataBound事件 protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { //这里可以在DataList1绑定后,获取每一个RadioButtonList RadioButtonList radioButtonList = e.Item.FindControl("RadioButtonList1") as RadioButtonList; } //这里是一个按钮,随意点击遍历这个DataList1的Item,来获取所选的值 protected void Button1_Click(object sender, EventArgs e) { foreach (DataListItem item in DataList1.Items) { RadioButtonList radioButtonList = item.FindControl("RadioButtonList1") as RadioButtonList; string value = radioButtonList.SelectedValue; } } 我有个问题能给个建议么~~?我在做一个在线考试的东西 ~学生端的~~你说用RadioButton好还是RadioButtonList好 每一道题答案都有:ABCD四个选项,还是用RadioButton好用。当然RadioButton也一样用就是了。 以前都没接触过这种~~以前都是直接用DataList或者GridView做添加修改删除~~现在第一次接触这种- -所以不知道什么下手 每一道题答案都有:ABCD四个选项,还是用RadioButton好用。当然RadioButton也一样用就是了。恩~用RadioButton 我知道用循环快~但是不知道什么下手~所以每个RadioButton 都要写一段代码 怎么才能ASP.NET中用Luncene.net实现全文索引 伪静态 页面里所有的链接都要改? asp.net怎样根据EXCEL的xlt格式的文件编程?? orcale 跟 sqlserver 有什么不同?送分了~~~`` ASP.net的用户控件问题 web中 treeview 节点右键点击也要选中问题 如何动态生成稍微复杂一点的表格,并在表格内添加上控件 timeoutexception的问题 小问题:如何知道某个值不在DropDownList中?谢谢! ▲▲▲微软专家,各位朋友请看过来:▲▲▲ 对某列里面的字符串处理,按一定规则排序 【再请教】为何删除文件后自动退出系统?
{
List<Survey> s = new List<Survey>();
s.Add(new Survey("1.1", "title 1"));
s.Add(new Survey("1.2", "title 1"));
s.Add(new Survey("1.3", "title 1"));
return s;
}这里是放在类里还是放在~新建的aspx里?- -刚刚入门问的问题有点内阁个~但是还是希望你能教教
{
if (!Page.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("name",typeof(string)),
new DataColumn("age",typeof(string))
}); DataRow dr = null; dr = dt.NewRow();
dr["name"] = "guwei";
dr["age"] = "30";
dt.Rows.Add(dr); dr = dt.NewRow();
dr["name"] = "google";
dr["age"] = "28";
dt.Rows.Add(dr); this.DataList1.DataSource = dt;
this.DataList1.DataBind();
}
} protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
RadioButtonList radioButtonList = e.Item.FindControl("RadioButtonList1") as RadioButtonList;
} protected void Button1_Click(object sender, EventArgs e)
{
foreach (DataListItem item in DataList1.Items)
{
RadioButtonList radioButtonList = item.FindControl("RadioButtonList1") as RadioButtonList;
string value = radioButtonList.SelectedValue;
} }<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server"
onitemdatabound="DataList1_ItemDataBound">
<ItemTemplate>
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Text="1" Value="1" />
<asp:ListItem Text="2" Value="2" />
<asp:ListItem Text="3" Value="3" />
</asp:RadioButtonList>
</ItemTemplate>
</asp:DataList>
</div>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</form>
</body>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//初始化一个Datatable
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("name",typeof(string)),
new DataColumn("age",typeof(string))
}); DataRow dr = null; dr = dt.NewRow();
dr["name"] = "guwei";
dr["age"] = "30";
dt.Rows.Add(dr); dr = dt.NewRow();
dr["name"] = "google";
dr["age"] = "28";
dt.Rows.Add(dr); //DataList绑定这个Datatable
this.DataList1.DataSource = dt;
this.DataList1.DataBind();
}
} //这个而是DataList1控件的ItemDataBound事件
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
//这里可以在DataList1绑定后,获取每一个RadioButtonList
RadioButtonList radioButtonList = e.Item.FindControl("RadioButtonList1") as RadioButtonList;
} //这里是一个按钮,随意点击遍历这个DataList1的Item,来获取所选的值
protected void Button1_Click(object sender, EventArgs e)
{
foreach (DataListItem item in DataList1.Items)
{
RadioButtonList radioButtonList = item.FindControl("RadioButtonList1") as RadioButtonList;
string value = radioButtonList.SelectedValue;
} }