using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
public partial class xgxz : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
string dsn = System.Configuration.ConfigurationManager.ConnectionStrings["dsn"].ToString();
SqlConnection con = new SqlConnection(dsn);
con.Open();
String SQL = "select top 6 newsid,newstitle,CONVERT(char(10), newstime, 102) AS newstime,newstype from news where newstype=61 ";
SqlDataAdapter sd = new SqlDataAdapter(SQL, con);
DataSet ds = new DataSet();
sd.Fill(ds, "news");
this.GridView1.DataSource = ds.Tables["news"].DefaultView;
this.GridView1.DataBind();
con.Close();
}
///
/// 截取字符串
///
/// 要截取的字符串
/// 规定该字符串显示的长度
///
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
e.Row.Cells[0].ToolTip = Str;
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)//数据行
{
string Str = e.Row.Cells[0].Text; //第二列内容
if (Str.Length > 10) //第二列内容大于20个
{
e.Row.Cells[0].Text = Str.Substring(0, 10) + "..."; //截取20个显示,其他用“...”号代替
e.Row.Cells[0].ToolTip = Str;//鼠标放上去显示全部信息
}
}
}
}
string Str;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)//数据行
{
Str = e.Row.Cells[0].Text; //第二列内容
if (Str.Length > 2) //第二列内容大于20个
{
e.Row.Cells[0].Text = Str.Substring(0, 2) + "..."; //截取20个显示,其他用“...”号代替
e.Row.Cells[0].ToolTip = Str;//鼠标放上去显示全部信息
}
}
还是不对。。。。没有效果的