数据库入门经典上的一个例子,现在是为什么我点复选框一点反应都没有<script runat="server">
private void page_load(object sender,System.EventArgs e)
{
string sql="select title,sid,inserttime from liuyan order by sid desc";
OleDbConnection conn=new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("liuyan.mdb"));
conn.Open();
OleDbDataAdapter da=new OleDbDataAdapter(sql,conn);
DataSet ds=new DataSet(); da.Fill(ds,"gggg");
bglist.DataSource=ds.Tables["gggg"];
bglist.DataBind(); conn.Close();}
private void checkchang(object s, System.EventArgs e)
{
bglist.Columns[2].Visible = chkShowAddressee.Checked;
//bglist.Columns[2].Visible = false;
}
</script>
</html>
<head></head>
<body>
<form id="dd" runat="server">
<asp:checkbox id="chkShowAddressee" runat="server" atuopostback="true" text="显示选项" oncheckchanged="checkchang"/>
<asp:datagrid id="bglist" runat="server" autogeneratecolumns="false">
<columns>
<asp:boundcolumn datafield="sid" headerText="自动编号" dataformatstring="#{0:D2}"/>
<asp:boundcolumn datafield="title" headertext="标题" />
<asp:boundcolumn datafield="inserttime" headertext="时间" visible="true" />
</columns>
</asp:datagrid>
</form>
</body>
</html>

解决方案 »

  1.   

    说一下,初始的时候这列是不显示的
    <asp:boundcolumn datafield="inserttime" headertext="时间" visible="false" />
      

  2.   

    是不是要设置checkbox的autopostback=true?
    just try^_^
      

  3.   

    private void checkchang(object s, System.EventArgs e)
    {
    bglist.Columns[2].Visible = chkShowAddressee.Checked;
    //bglist.Columns[2].Visible = false;
    }
    因为你是指定处理方法,所以checkchang的声明应为public
    public void checkchang(object s, System.EventArgs e)
    {
    bglist.Columns[2].Visible = chkShowAddressee.Checked;
    //bglist.Columns[2].Visible = false;
    }
      

  4.   

    晕..你是不是在那边有指定了默认的处理方法???你在.CS的下面这个方法:
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load);}
    里加上:
    this.bglist.CheckedChanged += new System.EventHandler(this.checkchang);