第一次加载网页可以绑定数据。。为什么点击完按钮 DataList显示不出我想要的数据呢
data newdata = new data();
private void Page_Load(object sender, System.EventArgs e)
{
//if(Session.Count==0) Page.Response.Redirect("../index.aspx");
if(!IsPostBack)
{
string Category_Display_Sql = "SELECT * FROM Category WHERE ({ fn LENGTH(Category_id) } = 9)";//"select * from Category";
Category_Display_BindGrid(Category_Display_Sql);
}
else
{
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
public void Category_Display_BindGrid(string Sql)
{
try
{
this.Category_DataList.DataSource= newdata.dbbind( Sql );
this.Category_DataList.DataBind();
}
catch(Exception)
{
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
string Sql = null;
if( this.CheckBoxList1.Items[0].Value =="一级分类" )
{
Sql = "SELECT * FROM Category WHERE ({ fn LENGTH(Category_id) } = 4)";
}
else if( this.CheckBoxList1.Items[1].Value =="二级分类" )
{
Sql = "SELECT * FROM Category WHERE ({ fn LENGTH(Category_id) } = 9)";
}
else if( this.CheckBoxList1.Items[2].Value =="三级分类" )
{
Sql = "SELECT * FROM Category WHERE ({ fn LENGTH(Category_id) } = 14)";
}
Category_Display_BindGrid(Sql);
}
}
}