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;

public partial class WebMain_Product_cart_wordlink : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand cmd = new SqlCommand("select top 10 title,href,alt from link where type='0' and isopen='y' order by addtime", conn);
        SqlDataReader sdr = cmd.ExecuteReader();
        TableRow tr;
        TableCell tc;
        HyperLink hl;  
        tr = new TableRow();
        while (sdr.Read())
        {
        tc = new TableCell();
        tc.HorizontalAlign = HorizontalAlign.Left;
        tr.CssClass = "";
        hl = new HyperLink();
        hl.Text =SubStr(sdr.GetString(0),15);
        hl.NavigateUrl = sdr.GetString(1);
        hl.Target = "_blank";
        hl.CssClass = "btn_link";
        tc.Controls.Add(hl);
        tr.Controls.Add(tc);
        }      
        TB.Controls.Add(tr);
        conn.Close();
    }
    public string SubStr(string sString, int nLeng)
    {
        if (sString.Length <= nLeng)
        {
            return sString;
        }
        string sNewStr = sString.Substring(0, nLeng);
        sNewStr = sNewStr + "...";
        return sNewStr;
    }
}
