zoukankan      html  css  js  c++  java
  • Gridview的中数据的截取

    后端代码:

    后端代码
    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 }
    怀揣着一点点梦想的年轻人
    相信技术和创新的力量
    喜欢快速反应的工作节奏
  • 相关阅读:
    0317复利计算的回顾与总结
    0518 Scrum 项目 5.0
    0517 Scrum 项目4.0
    0512 Scrum 项目3.0
    实验三 进程调度模拟程序
    0505 Scrum 项目1.0
    0502团队项目 SCRUM团队成立
    0428 团队项目2.0
    0422团队项目
    实验二 作业调度模拟程序
  • 原文地址:https://www.cnblogs.com/hfliyi/p/1964966.html
Copyright © 2011-2022 走看看