Telerik RadGridView 问题

发布于 2024-08-29 14:01:49 字数 1687 浏览 6 评论 0原文

我在我的项目中使用 Telerik RadGridView。我想在列中显示图像。

                GridViewImageColumn col1 = new GridViewImageColumn();
                col1.Width = 100;
                col1.DataMemberBinding = new Binding("id");
                col1.Header = "PhotoByConverter";
                col1.DataMemberBinding.Converter = new ThumbnailConverter();
                grid.Columns.Add(col1);


                GridViewDataColumn col2 = new GridViewDataeColumn();
                col2.Width = 100;
                col2.DataMemberBinding = new Binding("firstName");
                col2.Header = "Person name";
                grid.Columns.Add(col2);

                Grid.ItemsSource=DataTable;

第一列不工作,但第二列工作正常。我使用 Converter 来处理下面显示的图像,

    public class ThumbnailConverter : IValueConverter
    {

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
                    IEnumerable<thumbNail> result = from n in thumbnails
                                        where n.personID == value.ToString()
                                        select n;


        if (result != null && result.First().thumbnail != null)
        {
            return result.First().thumbnail.file;
        }
        else
        {
            return null;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new Exception("The method or operation is not implemented.");
    }
   }

我通过人的 id 缩略图找到并将其设置为 GridViewImageColumn 的数据。我用调试器检查了转换器工作正常。我无法理解为什么它不起作用。 有什么想法吗?

I am using Telerik RadGridView in my project. I want to show image in column.

                GridViewImageColumn col1 = new GridViewImageColumn();
                col1.Width = 100;
                col1.DataMemberBinding = new Binding("id");
                col1.Header = "PhotoByConverter";
                col1.DataMemberBinding.Converter = new ThumbnailConverter();
                grid.Columns.Add(col1);


                GridViewDataColumn col2 = new GridViewDataeColumn();
                col2.Width = 100;
                col2.DataMemberBinding = new Binding("firstName");
                col2.Header = "Person name";
                grid.Columns.Add(col2);

                Grid.ItemsSource=DataTable;

First column not wokrs but second works fine. I use Converter for image shown below

    public class ThumbnailConverter : IValueConverter
    {

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
                    IEnumerable<thumbNail> result = from n in thumbnails
                                        where n.personID == value.ToString()
                                        select n;


        if (result != null && result.First().thumbnail != null)
        {
            return result.First().thumbnail.file;
        }
        else
        {
            return null;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new Exception("The method or operation is not implemented.");
    }
   }

I found by id thumbnail of person and set it like data for GridViewImageColumn. I checked with Debuger conveter works properly. I can't undesrtand why it doesn't work.
Any ideas?

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

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

发布评论

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

评论(1

柠檬色的秋千 2024-09-05 14:01:49

我找到了这些问题的解决方案。唯一需要的是使用方括号中的属性名称

    GridViewImageColumn col1= new GridVeiwImageColumn();
    col1.DataMemberBinding = new Binding("[id]");

I found solution for these problem. Only thing that is require is use Property name in square brackets

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