如何使Label带有链接??此法感觉有点取巧!!!

关键代码

/**************************************************************第一行*********************************************************************************************/
using (SqlConnection conn = new SqlConnection())
{
// 数据库连接字符串
conn.ConnectionString = "Initial Catalog=hqc;Data Source= JTKP;Integrated Security=True";
string sql = "select them,addtime from tb_News where id = '1'";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
HtmlTableRow row1 = new HtmlTableRow();
HtmlTableCell cell1 = new HtmlTableCell();
Image img1 = new Image();
img1.ImageUrl = "~/picture/000.gif";
cell1.Controls.Add(img1);
row1.Controls.Add(cell1);

cell1 = new HtmlTableCell();
cell1.Attributes.Add("width", "85%");
cell1.Attributes.Add("height", "5%");
HyperLink a = new HyperLink();
Label l1 = new Label();
l1.Text = dr.GetString(0);
a.Text = l1.Text;
a.NavigateUrl = "~/NewSation/News.aspx";
a.Attributes.Add("target", "_top");
cell1.Controls.Add(a);
row1.Controls.Add(cell1);


cell1 = new HtmlTableCell();
cell1.Attributes.Add("width", "15%");
cell1.Attributes.Add("height", "5%");
Label l2 = new Label();
l2.Text = dr.GetDateTime(1).ToString("d");
cell1.Controls.Add(l2);
row1.Controls.Add(cell1);
xinwen.Rows.Add(row1);
}
dr.Close();
conn.Close();
}

效果

效果

善守者藏于九地之下, 善攻者动于九天之上
原文地址:https://www.cnblogs.com/jiutiankunpeng/p/4511603.html