namespace TestWeb
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindsData();
        }
        protected void BindsData()
        {
            Database cd = DatabaseFactory.CreateDatabase();
            DbCommand ds = cd.GetSqlStringCommand("select * from quanxian");
            try
            {
                //
                DataTable tb = cd.ExecuteDataSet(ds).Tables[0];
                //
                this.GridView1.DataSource = tb;
                this.GridView1.DataBind();
            }
            catch (Exception ex)
            {
                string err = ex.Message;
                //
                Response.Write(err);            }
            finally
            {
              if (ds != null) ds.Dispose();
            }
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            Response.Write("wwww");
            CheckBox cb = (CheckBox)e.Row.FindControl("checkbox1");
            DataRowView gvr = (DataRowView)e.Row.DataItem;
            if (cb != null)
            {
                Response.Write(gvr["adds"].ToString());
                Response.Write("sss");
                if (gvr["adds"].ToString() == "1")
                {
                    cb.Checked = true;                }            }
        }    }
}

解决方案 »

  1.   

    Response.Write("wwww");
    本来是Response.Write("wwww");我是想引起大家注意,加个颜色。没加成。
    就是这行代码为什么没有执行。
      

  2.   

    BindsData();
    加个if(!Page。IsPostBack){
    BindsData();
    }
      

  3.   

    RowDataBound事件有没有触发
    看看网页源代码的第一行有没有设一个断点调试一下
      

  4.   

    还是不行啊。没有显示www。也没提示错误。 
      

  5.   

    在Response.Write("wwww");加个断点看看能进来不
      

  6.   

    测试了下。没有触发RowDataBound,也不知道怎么搞的。可数据绑定成功了啊。
      

  7.   

    有没有加上这句:AutoEventWireup="true"
      

  8.   

    解决了。谢谢。
            <asp:GridView ID="GridView1" runat="server"  Width="538px" 
                AutoGenerateColumns="False"  OnRowDataBound="GridView1_RowDataBound">OnRowDataBound="GridView1_RowDataBound"这个事件不晓得什么时候去掉了。
    结帖 分平分啊。