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;
using sql;

public partial class showNews : System.Web.UI.Page
{
    Operation operate = new Operation();
    SqlDB sqldb = new SqlDB();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitNews();
            string sqlStr = "select * from news";
            operate.DataListBind(DataListNews, sqlStr);
        }
    }
    /// <summary>
    /// 页面初始化或首页传入参数时执行
    /// </summary>
    private void InitNews()
    {
        string newsId = "";
        try
        {
            newsId = Request.QueryString["id"].ToString();
        }
        catch (Exception e)
        {
        }
        finally
        {
            if (newsId.Trim().Length == 0)
            {
                // newsId = "1";
               Response.Redirect("err.aspx");
            }
        }
        string strSql = "select * from news where newsId=" + newsId;
        DataBindControl(strSql);
    }
    /// <summary>
    /// 单击新闻列表中的一项时页面显示
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnShow_Command(object sender, CommandEventArgs e)
    {
        string newsId = e.CommandArgument.ToString();
        string strSql = "select * from news where newsId=" + newsId;
        DataBindControl(strSql);
    }
    /// <summary>
    /// 将新闻信息绑定到页面上的所有Literal控件
    /// </summary>
    /// <param name="strSql"></param>
    private void DataBindControl(string strSql)
    {
        DataSet ds = sqldb.GetDS(strSql);
        ltTitle.Text = ds.Tables[0].Rows[0][1].ToString();
        ltDetails.Text = ds.Tables[0].Rows[0][3].ToString();
        ltDate.Text = ds.Tables[0].Rows[0][4].ToString();
        ds.Clear();
    }
}
