62,242
社区成员




public static DataTable GetTop8News()
{
string sql = "select top 8 * from T_News where newID=1 order by newsTime desc ";
DataTable dt = DataHelp.ExcuteSqlReturnTable(sql);
return dt;
}
public static DataTable ExcuteSqlReturnTable(string sql)
{
try
{
SqlCommand command = new SqlCommand(sql, connection);
SqlDataAdapter adpater = new SqlDataAdapter(command);
DataTable dt = new DataTable();
adpater.Fill(dt);
return dt;
}
catch (Exception ex)
{
return null;
}
}
public void NewsDataGridViewBind()
{
DataTable dt = NewBusiness.GetTop8News();
GridViewNew.DataSource=dt;//GridViewNew是GridView的ID
GridViewNew.DataBind();
}
protected void gv_Test_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.DataRow)
{
if (e.Row.Cells[0].Text.length>10)
{
e.Row.Cells[0].Text=e.Row.Cells[0].Text.Substring(1, 10)+"……";
}
}
}
protected void gv_Test_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.DataRow)
{
if (e.Row.Cells[0].Text.length>100)
{
e.Row.Cells[0].Text=e.Row.Cells[0].Text.Substring(1, 100)+"……";
}
}
}