asp.net 获取checkboxlist值

RT:.net生成HTML页面中.checkbox的值是放在label中的.我要在后台如何获取选中的值?checkbox是动态生成的,值和id都是读的数据库... RT:.net生成HTML页面中.checkbox的值是放在label中的.我要在后台如何获取选中的值?checkbox是动态生成的,值和id都是读的数据库 展开
 我来答
匿名用户
2013-08-12
展开全部
//循环新建CheckBox控件
for (int i = 0; i < 3; i++)
{
CheckBox cb = new CheckBox();
cb.Text = "第" + i + "个";
cb.Checked = true;
Label1.Controls.Add(cb);
}
//循环访问Label里面的控件
foreach (var item in Label1.Controls)
{
//如果控件为CheckBox就执行
if (item is CheckBox)
{
//先将控件转换为CheckBox以调用它的Checked属性
CheckBox cb = item as CheckBox;
//输出勾选的CheckBox
if (cb.Checked == true)
Response.Write(cb.Text);
}
}
匿名用户
2013-08-12
展开全部
public void bindTP()
{
DataSet ds = ps.GetAllTP();
GridView2.DataSource = ds;
GridView2.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Request.Cookies["aa"] != null)
{
foreach (GridViewRow myrow in GridView2.Rows)
{
RadioButton cc = (RadioButton)myrow.Cells[0].FindControl("RadioButton1");
if (cc.Checked)
{
Response.Write("<script>alert('找屎啊,投过还投!!') </script>");
cc.Checked = false;
return;
} }
}
else
{
foreach (GridViewRow myrow in GridView2.Rows)
{
RadioButton cb = (RadioButton)myrow.Cells[0].FindControl("RadioButton1");
if (cb.Checked)
{
int TP_ID = Convert.ToInt32(myrow.Cells[1].Text);
int i = ps.Updata_TP_Sum(TP_ID);
if (i > 0)
{
Response.Cookies["aa"].Value = Request.UserHostAddress.ToString();
Response.Cookies["aa"].Expires = DateTime.Now.AddMinutes(1);
Response.Write("<script>alert('感谢您对本站的支持!!!') </script>");
cb.Checked = false; } } 这是我做投票时的源码,希望能对你有帮助
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式