如何显示gridview中的前100个字符? [英] How to display the first 100 characters in a gridview?

查看:91
本文介绍了如何显示gridview中的前100个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用gridview来显示数据,但是有时数据会很大以显示在单元格中。我可以使用一种方法来允许gridview显示f.e.字符串的前100个字符?



欢迎任何帮助!

您可以处理GridView的RowDataBound事件并剪切文本长度,如下所示:

  protected void gvNotes_RowDataBound(object (e.RowIndex< 0)
return;

int _myColumnIndex = 0; //在这里替换你的值

string text = e.Row.Cells [_myColumnIndex] .Text;

if(text.Length> 100)
{
e.Row.Cells [_myColumnIndex] .Text = text.Substring(0,100);
}
}


I use a gridview to display data, but sometimes the data is to big to be displayed in a cell. Can I use a method to allow the gridview to display f.e. the first 100 characters of a string?

any help is welcome!

解决方案

You can handle the RowDataBound event of the gridview and cut the text length, like so:

protected void gvNotes_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowIndex < 0)
        return;

    int _myColumnIndex = 0;   // Substitute your value here

    string text = e.Row.Cells[_myColumnIndex].Text;

    if (text.Length > 100)
    {
        e.Row.Cells[_myColumnIndex].Text = text.Substring(0, 100);
    }
}

这篇关于如何显示gridview中的前100个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆