DataList限制字符个数,多出的用 ......

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        foreach (DataListItem dt in this.DataList1.Items)
        {

            Label lb = (Label)e.Item.FindControl("Label1");

            string Test1 = lb.Text;

            string lbtest1 = "";

            if (Test1.Length > 8)
            {
                lbtest1 = Test1.Substring(0, 8);
                lb.Text = lbtest1 + "......";
            }
            else
            {
                lb.Text = Test1.ToString();

            }

        }

    }

posted on 2007-07-19 09:16  一路前行  阅读(387)  评论(0编辑  收藏  举报