public void con_news()
{
Class1 con_yj = new Class1();
DataSet ds = new DataSet();
DataTable dt = new DataTable("testif");
//创建表列名
DataColumn dcdate = new DataColumn("date", typeof(System.String));
DataColumn dcpic = new DataColumn("pic", typeof(System.String));
DataColumn dctitle = new DataColumn("title", typeof(System.String));
DataColumn dcid = new DataColumn("id", typeof(System.String));
DataColumn dcauthor = new DataColumn("author", typeof(System.String));
//添加表列名
dt.Columns.Add(dcid);
dt.Columns.Add(dctitle);
dt.Columns.Add(dcpic);
dt.Columns.Add(dcdate);
dt.Columns.Add(dcauthor);
//添加内容
for (int i = 0; i < con_yj.con("select top 5 * from news_info").Tables[0].Rows.Count; i++)
{
DataRow row = dt.NewRow();
if (Convert.ToInt32(con_yj.con("select datediff(dd,new_date,getdate()) from news_info order by new_date desc").Tables[0].Rows[i][0].ToString()) <= 1)
{
row[2] = "img/news.jpg";
}
else
{
row[2] = "img/new.jpg";
}
row[0] = con_yj.con("select * from news_info order by new_date desc").Tables[0].Rows[i]["new_number"].ToString();
if (con_yj.con("select * from news_info order by new_date desc").Tables[0].Rows[i]["new_rubric"].ToString().Length > 25)
{
row[1] = con_yj.con("select * from news_info order by new_date desc").Tables[0].Rows[i]["new_rubric"].ToString().Substring(0, 25) + "......";
}
else { row[1] = con_yj.con("select * from news_info order by new_date desc").Tables[0].Rows[i]["new_rubric"].ToString(); }
row[3] = con_yj.con("select * from news_info order by new_date desc").Tables[0].Rows[i]["new_date"].ToString().Substring(0, 10);
dt.Rows.Add(row);
}
DataView dv = new DataView(dt);
//dv.Sort = "date desc";
dl1.DataSource = dv;
dl1.DataBind();
}
昨天写的新闻显示的一段代码。。。应该可以解决你问的问题了。。