获取Gridview的HyperLinkField的Text文本

来源:互联网 发布:mac 微信字体设置 编辑:程序博客网 时间:2024/05/14 11:58

今天用Gridview绑定一个超链接列HyperLinkField

文本太长想用...代替,弄了半天终于给做出来了。

平时取BoundField的Text值的时候,直接在DataBound时间里面e.Row.Cell[0].Text就行

但是HyperLinkField这样写怎么也取不到,必须把HyperLinkField列转换成HyperLink

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HyperLink hl = (HyperLink)e.Row.Cells[0].Controls[0];
                if (hl.Text.Length > 20)
                {
                    hl.Text = hl.Text.Substring(0, 19) + "...";
                }
            }
        }

这样就能对HyperLinkField的文本进行操作了

 

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/pgameli/archive/2009/05/19/4201431.aspx