- 爱易网页
-
ASP.NET教程
- 初学者有关问题:GridView 与 CheckBox 多选 有关问题 ()
日期:2014-05-18 浏览次数:20586 次
菜鸟问题:GridView 与 CheckBox 多选 问题 (求助)
我的想法是选中Checkbox后,点击按钮,输出1111111,否则输出22222,在网上看了很多代码,但一直实现不了。麻烦请看代码
前台:
<asp:Button id= "MarkInvalid " runat= "server " text= "测试 " OnClick= "MarkInvalid_Click " >
<asp:GridView ID= "GridView1 " runat= "server " AutoGenerateColumns= "False " >
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:CheckBox ID= "selectNoAct " runat= "server " />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField />
</Columns>
</asp:GridView>
后台程序:
public void MarkInvalid_Click(object sender, EventArgs e)
{
foreach (GridViewRow i in GridView1.Rows)
{
CheckBox cSelect = (CheckBox)i.FindControl( "selectNoAct ");
if (cSelect.Checked == true)
{
Response.Write( "1111111 ");
}
else
Response.Write( "2222222 ");
}
}
先谢谢啦
------解决方案--------------------
function Seldchk()
{
var element = document.getElementsByTagName( "input ");
for(var i=0; i <element.length; i++){
if (element[i].type == "checkbox ")
{
if (element[i].checked == true)
{
alert( "1111 ");
}
else
{
alert( "22222 ");