111,130
社区成员
发帖
与我相关
我的任务
分享 protected void Button1_Click(object sender, EventArgs e)
{
string buystr = "";
for (int i = 0; i < 2; i++)
{
CheckBox chk = (CheckBox)FindControl("CheckBox" + i.ToString());
//CheckBox chk = (CheckBox)DataList1.Items[i].FindControl("CheckBox1");
if (chk.Checked)//这一行老是提示 未将对象引用设置到对象的实例。是没获取到CheckBox控件吗?
{
string id = chk.Text;
buystr = buystr + id + ",";
Response.Write("<script>alert('"+buystr+"');</script>");
}
}
if (buystr == "")
{
Response.Write("<script>alert('未选择任何选项!');</script>");
}
else
{
Response.Write("<script>alert('" + buystr + "');</script>");
//Session["strbuy"] = buystr;
//Response.Redirect("Shopping.aspx");
}
}