在Page_Load方法里
RadioButtonList objRadioButtonList = new RadioButtonList();
VoteArray为从别处取到值的一个数组
for (int i = 0; i < VoteArray.Length; i++)
{
objRadioButtonList.Items.Add(VoteArray[i]);
//InAll = InAll + Convert.ToInt32(votenum[i]);
}
objRadioButtonList.ID = "radio1";
PlaceHolder1.Controls.Add(objRadioButtonList);
在一个按钮的单击事件里buttonsend_click
for (int j = 0; j < VoteArray.Length; j++)
{
if (radio1.SelectedIndex== VoteArray[j])
{
VotenumArray[j] = Convert.ToString(Convert.ToInt32(VotenumArray[j]) + 1);
}
}
提示“当前上下文不存在‘radio1’”弄了好几个小时了,请前辈赐教,在线等,谢谢
RadioButtonList objRadioButtonList = new RadioButtonList();
VoteArray为从别处取到值的一个数组
for (int i = 0; i < VoteArray.Length; i++)
{
objRadioButtonList.Items.Add(VoteArray[i]);
//InAll = InAll + Convert.ToInt32(votenum[i]);
}
objRadioButtonList.ID = "radio1";
PlaceHolder1.Controls.Add(objRadioButtonList);
在一个按钮的单击事件里buttonsend_click
for (int j = 0; j < VoteArray.Length; j++)
{
if (radio1.SelectedIndex== VoteArray[j])
{
VotenumArray[j] = Convert.ToString(Convert.ToInt32(VotenumArray[j]) + 1);
}
}
提示“当前上下文不存在‘radio1’”弄了好几个小时了,请前辈赐教,在线等,谢谢
解决方案 »
- 网页快照保存的是哪些内容呀?除了文本,包括图片等信息吗?
- 请教个问题...在服务器端获得Repeater中某行的某个单元格的值(.net).....在线等
- datalist嵌套datalist 内嵌datalist 的删除问题?
- ASP.net2.0可以用DataGrid吗?
- 帮我解释一下SqlParameter对象相关的两句代码..谢谢~
- 关于使用C#截取字符串
- 求救:关于更新时的并发冲突
- 怎么将数据库中的表显示在网页上
- 如何把通过存储过程取出的数据放入DataSet
- “DataGridTest.WebForm2”不是有效的类型,怎么解决这个问题?
- 大家帮忙看看,做这样一个网站要多少米?
- 怎么样才能在客户数据绑定gridview
你该在页面的class里面申明个变量 protected RadioButtonList objRadioButtonList;
这样才能算是Page的成员 要不你怎么找到控件呢?下面的代码我测试成功
public class CSDN : System.Web.UI.Page
{
protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1;
protected System.Web.UI.WebControls.Button Button1;
protected Button btnTest;
private void Page_Load(object sender, System.EventArgs e)
{
btnTest = new Button();
btnTest.Text = "您好";
PlaceHolder1.Controls.Add(btnTest);
} private void Button1_Click(object sender, System.EventArgs e)
{
btnTest.Enabled = false;
}
}
for (int j = 0; j < VoteArray.Length; j++)
{
if (radio1.SelectedIndex== VoteArray[j])
{
VotenumArray[j] = Convert.ToString(Convert.ToInt32(VotenumArray[j]) + 1);
}
}
try: RadioButtonList radio1=(RadioButtonList)PlaceHolder1.FindControl("radio1"); for (int j = 0; j < VoteArray.Length; j++)
{
if (radio1.SelectedIndex== VoteArray[j])
{
VotenumArray[j] = Convert.ToString(Convert.ToInt32(VotenumArray[j]) + 1);
}
}
我回答过了,不知道可不可以用啊
(RadioButtonList)PlaceHolder1.FindControl("radio1");
protected void Page_Load(object sender, EventArgs e)
{
RadioButtonList objRadioButtonList = new RadioButtonList();
for (int i = 0; i < VoteArray.Length; i++)
{
objRadioButtonList.Items.Add(VoteArray[i].ToString());
//InAll = InAll + Convert.ToInt32(votenum[i]);
}
objRadioButtonList.ID = "radio1";
PlaceHolder1.Controls.Add(objRadioButtonList); }
protected void btn_Vote_Click(object sender, EventArgs e)
{
RadioButtonList radio1 = (RadioButtonList)PlaceHolder1.FindControl("radio1");
for (int j = 0; j < VoteArray.Length; j++)
{
if (radio1.SelectedIndex == VoteArray[j])
{
//VotenumArray[j] = Convert.ToString(Convert.ToInt32(VotenumArray[j]) + 1);
//Response.Write("<script language='javascript'>alter(" + radio1.SelectedIndex + ");</script>");
Vote.Text = radio1.SelectedIndex.ToString();
}
}
}
同时感谢Brookes(边走边唱),cat_hsfz(我的Blog在http://purl.oclc.org/NET/cathsfz)的提点