注册 登录
编程论坛 ASP.NET技术论坛

GridView问题

dengjifu 发布于 2007-11-30 11:01, 804 次点击
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class admin_gridview : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
       foreach(GridView gr in GridView1.Rows)
       {
           CheckBox chk = (CheckBox)gr.Cells[5].FindControl["chk"];
           if (chk.Checked)
           {
               chk.Checked = false;
           }
           else
           {
               chk.Checked = true;
           }
       }
    }
}

[bold]编译器错误信息: [/bold]CS0117: “System.Web.UI.WebControls.GridView”并不包含“Cells”的定义
4 回复
#2
人妖1232007-11-30 11:20
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            if (cbox.Checked == true)
            {
           }
}
#3
洁洁2007-11-30 11:29
CheckBox chk = (CheckBox)gr.Rows[i].Cells[5].FindControl("chk");

[[italic] 本帖最后由 洁洁 于 2007-11-30 11:30 编辑 [/italic]]
#4
dengjifu2007-11-30 12:56
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
       foreach(GridViewRow gr in GridView1.Rows)
       {
           CheckBox chk = (CheckBox)gr.Cells[5].FindControl("sz");
           if (chk.Checked)
           {
               chk.Checked = false;
           }
           else
           {
               chk.Checked = true;
           }
       }
#5
冰镇柠檬汁儿2007-11-30 13:20
怎么了?标红,有什么问题吗?
1