如何取出panel里的Radion里的值
我动态生成了一些RadionButtonList代码是这样的:string str1=ds2.Tables[0].Rows[0]["A"].ToString
string str2=ds2.Tables[0].Rows[0]["B"].ToString();
string str3=ds2.Tables[0].Rows[0]["C"].ToString();
string str4=ds2.Tables[0].Rows[0]["D"].ToString();
RadioButtonList rad=new RadioButtonList();
rad.Items.Add("A:"+str1);
rad.Items.Add("B:"+str2);
rad.Items.Add("C:"+str3);
rad.Items.Add("D:"+str4);
rad.ID="rad"+m.ToString();
this.Panel1.Controls.Add(rad);
运行后当我点A选项的时候能够取出A的值 如何实现?在panel里把控件的值取出来
--------------------编程问答-------------------- this.Panel1.Controls[0].Text ? --------------------编程问答-------------------- 我知道可以用Panel1.FindControl取的,但是语法是怎么样的?我要取出RadionButtonList的选项的值 --------------------编程问答--------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
RadioButtonList rad = new RadioButtonList();
rad.Items.Add("A:" );
rad.Items.Add("B:");
rad.Items.Add("C:");
rad.Items.Add("D:");
rad.ID = "rad";
rad.AutoPostBack = true;//设置向服务器提交
this.Panel1.Controls.Add(rad);
rad.SelectedIndexChanged += new EventHandler(rad_SelectedIndexChanged);
}
void rad_SelectedIndexChanged(object sender, EventArgs e)
{
RadioButtonList rad =(RadioButtonList)Panel1.FindControl("rad");
Response.Write("你选择的是:" + rad.SelectedValue);
}
}
--------------------编程问答-------------------- 上面的就行。
aspx页面代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px">
</asp:Panel>
</form>
</body>
</html>
补充:.NET技术 , C#