工作中点滴记录

永远保持学徒心态

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

后端代码:

后端代码
1 protected void Page_Load(object sender, EventArgs e)
2 {
3 if (!IsPostBack)
4 {
5 databind();
6 }
7
8 }
9 public void databind()
10 {
11 SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ToString());
12 SqlCommand cmd = new SqlCommand();
13 cmd.Connection = con;
14 cmd.CommandText = "Select * From Customers";
15 SqlDataAdapter da = new SqlDataAdapter(cmd);
16 DataSet ds = new DataSet();
17 da.Fill(ds);
18 this.GridView1.DataSource = ds.Tables[0];
19 this.GridView1.DataKeyNames = new string[] { "CustomerID" };
20 this.GridView1.DataBind();
21 }
22 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
23 {
24 if (e.Row.RowType == DataControlRowType.DataRow)
25 {
26 e.Row.Cells[1].Text = SubstringStr(e.Row.Cells[1].Text, 5);
27 }
28 }
29 public string SubstringStr(string str, int len)
30 {
31 if (str.Length <= len)
32 {
33 return str;
34 }
35 else
36 {
37 return str.Substring(0, len) + "...";
38 }
39 }
posted on 2011-02-25 15:50  梦里故乡  阅读(254)  评论(0编辑  收藏  举报