如何在asp.net中的gridview中读取模板控件的属性 [英] how to read the properties of a template control in gridview in asp.net
本文介绍了如何在asp.net中的gridview中读取模板控件的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在asp.net中使用带有复选框类型的模板字段的gridview.我想在运行时并使用以下代码来检索复选框的值..但不适用于我,请帮助
I am using a gridview in asp.net with a template field of type checkbox. I wanna retrieve the value of checkbox at runtime and using the following code..but its not working for me please help
foreach (GridViewRow row in GridView1.Rows)
{
if (row.Cells[1].Text.ToString() == "True" || row.Cells[1].Text.ToString() == "1")
{
rtag = rtag + "1";
}
else
{
rtag = rtag + "0";
}
}
推荐答案
尝试以下代码.
Try this code.
foreach (GridViewRow row in GridView1.Rows)
{
bool isChecked = ((CheckBox) row.FindControl("YourCheckBoxID")).Checked;
if (isChecked)
{
rtag = rtag +"1"
}
else
{
rtag = rtag + "0"
}
}
尝试以下示例.
Hi try the below sample.
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox chk = (CheckBox)row.FindControl("YourCheckBoxID");
if (chk.Checked)
{
//logic to implement when check box is checked
}
else
{
//logic to implement when check box is not checked
}
}
这篇关于如何在asp.net中的gridview中读取模板控件的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文