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 Includes_New_Left : System.Web.UI.UserControl
{
    BLL.News news = new BLL.News();
    BLL.Class_1 c_1 = new BLL.Class_1();
    BLL.Class_2 c_2 = new BLL.Class_2();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitData();
            Bind();
        }
    }
    protected void Bind()
    {
        this.Rpt_Recommend.DataSource = news.getNewslisttop(9, 6, 12, "");
        this.Rpt_Recommend.DataBind();
        this.Rpt_new.DataSource = news.getNewslisttop(9, 0, 0, "");
        this.Rpt_new.DataBind();
    }
    protected void Btn_search_Click(object sender, EventArgs e)
    {
        Response.Redirect("New_List.aspx?class1=" + ddl1.SelectedValue + "&class2=" + ddl2.SelectedValue +
            "&key=" + this.valuekey.Value);
    }
    /// <summary>
    /// 绑定下拉框
    /// </summary>
    private void InitData()
    {
        DataTable dt = c_1.Class_1list("");
        ddl1.Items.Add(new ListItem("全部大类", "0"));
        ddl2.Items.Add(new ListItem("全部小类", "0"));
        foreach (DataRow dr in dt.Rows)
        {
            ddl1.Items.Add(new ListItem(dr["ClassName"].ToString(), dr["ClassID_1"].ToString()));
        }
    }
    protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(ddl1.SelectedValue);
        DataTable dt = c_2.Class_2list(id, "");
        ddl2.Items.Clear();
        ddl2.Items.Add(new ListItem("全部小类", "0"));
        foreach (DataRow dr in dt.Rows)
        {
            ddl2.Items.Add(new ListItem(dr["Class_2name"].ToString(), dr["ClassID_2"].ToString()));
        }
    }
}
