设置 radgrid 中字符串的最大长度/使用自动生成列限制 radgrid 中的字符串长度

发布于 2025-01-04 21:54:08 字数 315 浏览 0 评论 0原文

有什么方法可以告诉 radgrid 截断其列中字符串的长度吗?我使用 radgrid 来显示来自 sql 视图的数据,该视图具有多个(很多很多)字段,所以我想使用 autogeneratefields="true" 而不是设置所有 gridboundcolumns,和/或在 itemdatabound 中进行截断事件或类似的事情。

我想我也可以这样问,从视图中获取数据并使字段仅返回前 x 个字符的好方法是什么?正如我所说,有很多字段,所以我不想对我的 dal 中的每一列进行编码并执行子字符串或类似的操作......

有什么想法吗?

谢谢!

生锈的

Is there any way to tell a radgrid to truncate the length of strings in its columns? Im using a radgrid to show data from a sql view which has several (many, many) fields, so I want to use the autogeneratefields="true" rather than setting up all of the gridboundcolumns, and/or doing the truncation in the itemdatabound event or anything like that.

I suppose I could ask it this way also, what would be a good approach to getting data back from a view and have the fields only return the first x number of characters? As I said there are many fields so I don't want to have to code out every column in my dal and do a substring or something like that....

Any thoughts?

Thanks!

Rusty

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

意中人 2025-01-11 21:54:08

不确定我的问题是否有意义,但如果有人遇到类似的情况,我最终会循环遍历对象的属性并在 radgrid 上设置数据源之前截断字符串。

public static void SM_Dump_TruncStrings(ref List<myDataType> dump, int maxLength, bool addEllipses)
    {
        foreach (var sm in dump)
        {
            PropertyInfo[] infos = sm.GetType().GetProperties();
            foreach (var info in infos)
            {
                if (info.PropertyType == typeof(string))
                {
                    var origValue = info.GetValue(sm, null) as string;
                    if (origValue != null && origValue.Length > maxLength)
                    {
                        var newVal = origValue.Substring(0, maxLength);
                        if (addEllipses)
                            newVal += "...";
                        info.SetValue(sm, newVal, null);
                    }
                }
            }
        }
    }

这种方法取自此处:如何迭代自定义 vb.net 对象的每个属性?

干杯,

生锈了

Not sure if my question made sense, but in case anyone comes across a similar scenario, I ended up looping through my object's properties and truncated the strings before setting the datasource on the radgrid.

public static void SM_Dump_TruncStrings(ref List<myDataType> dump, int maxLength, bool addEllipses)
    {
        foreach (var sm in dump)
        {
            PropertyInfo[] infos = sm.GetType().GetProperties();
            foreach (var info in infos)
            {
                if (info.PropertyType == typeof(string))
                {
                    var origValue = info.GetValue(sm, null) as string;
                    if (origValue != null && origValue.Length > maxLength)
                    {
                        var newVal = origValue.Substring(0, maxLength);
                        if (addEllipses)
                            newVal += "...";
                        info.SetValue(sm, newVal, null);
                    }
                }
            }
        }
    }

This approach was taken from here : How to iterate through each property of a custom vb.net object?

cheers,

rusty

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文