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 System.Data.SqlClient;
using System.Text;
public partial class include_Hotnews : System.Web.UI.UserControl
{
    StringBuilder mystr = new StringBuilder();
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!Page.IsPostBack)
        {
            Showhotnews();
        }
    }
    //显示
    private void Showhotnews()
    {
        DataSet ds = Getnews();
        mystr.Remove(0, mystr.Length);
        mystr.Append("<table>");
        for (int i = 0; i < ds.Tables["aa"].DefaultView.Count; i++)
        {
            string newstitle = ds.Tables["aa"].Rows[i][1].ToString();
            if (newstitle.Length > 15)
            {
                newstitle = newstitle.Substring(0, 15);
            }
            mystr.Append("<tr><td>");
            mystr.Append("<a href='shownews.aspx?ShowID="+ds.Tables["aa"].Rows[i][0].ToString()+"' target='_blank'>◎ " + newstitle + "</a>"); 
            mystr.Append("</td></tr>");
        }
        mystr.Append("</table>");
        lblTitle.Text = mystr.ToString();
    }
    //打开新闻数据库
    public DataSet Getnews()
    {
        SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MYCONNECTIONSTRING"].ConnectionString);
        string cmdText = "SELECT TOP 15 MynewsID,Title,Createdate FROM Mynews ORDER BY Hit DESC";
        SqlDataAdapter da = new SqlDataAdapter(cmdText, myConnection);
        DataSet ds = new DataSet();
        try
        {
            myConnection.Open();
            da.Fill(ds, "aa");
        }
        catch (SqlException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        finally
        {
            myConnection.Close();
        }
        return ds;
    }
    protected string Mytitle(string sTitle)
    {
        if (sTitle.Length > 15)
        {
            sTitle = sTitle.Substring(0, 18);
        }
        return sTitle;
    }
}
