截断AspxGridView单元格中的文本

时间:2011-08-17 23:05:06

标签: devexpress truncate aspxgridview

有没有办法截断AspxGridView单元格中的长文本?

我已阅读并实施此解决方案。 ,http://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridViewASPxGridView_CustomColumnDisplayTexttopic

...当然可以工作但仅适用于一列,我需要使用多列创建它。

到目前为止,这是我的解决方案

protected void AsPxGridView1CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e)
{
    if (e.Column.FieldName != "AnalysisFeedbackAuto") return;
    if (e.Value.ToString().Length > 13)
    {
        var displayText = Regex.Replace(e.Value.ToString(), "<.*?>", string.Empty).Substring(0, 10);
        e.DisplayText = string.Concat(displayText, "...");
    }
}

有什么建议吗?

谢谢

===更新=== 显然这是解决方案

protected void AsPxGridView1CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e)
{
    if (e.Column.FieldName == "AnalysisFeedbackAuto" 
        || e.Column.FieldName == "AnalysisResults"
        || e.Column.FieldName == "AnalysisAnswers"
        )
    {
        if (e.Value.ToString().Length > 13)
        {
            var displayText = Regex.Replace(e.Value.ToString(), "<.*?>", string.Empty).Substring(0, 10);
            e.DisplayText = string.Concat(displayText, "...");
        }
    }
}

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:1)

protected void AsPxGridView1CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e)
{
    if (e.Column.FieldName == "AnalysisFeedbackAuto" 
        || e.Column.FieldName == "AnalysisResults"
        || e.Column.FieldName == "AnalysisAnswers"
        )
    {
        if (e.Value.ToString().Length > 13)
        {
            var displayText = Regex.Replace(e.Value.ToString(), "<.*?>", string.Empty).Substring(0, 10);
            e.DisplayText = string.Concat(displayText, "...");
        }
    }
}