将图片添加到GridViewImageColumn中

时间:2014-08-08 10:09:01

标签: c# .net telerik radgridview

我尝试将图片添加到GridViewImageColumn并找到this教程

这是我的代码(来自上面的链接):

GridViewImageColumn imageColumn = new GridViewImageColumn();
imageColumn.Name = "ImageColumn";
imageColumn.FieldName = "Photo";
imageColumn.HeaderText = "Picture";
imageColumn.ImageLayout = ImageLayout.Zoom;           
radGridView1.MasterTemplate.Columns.Insert(4, imageColumn);

所以我的问题是我需要指定图像路径的步伐?

3 个答案:

答案 0 :(得分:1)

试试这个

折叠imageGridImageColumn

GridImageColumn中的每个单元格都包含一个图像。要指定该图像的图像URL,您可以执行以下操作之一:

Set the ImageUrl property to a static value. When you use this method, every image appears the same in the entire column.

Set the DataImageUrlFields property to a field in the source that can be used to supply the image path and format it by setting the DataImageUrlFormatString property. You can specify multiple fields if the image URL is determined by more than one field in the database.

Set the DataAlternateTextField property to specify by which field in the grid source the column will be sorted/filtered. For the filtering, you must also explicitly set the DataType property of the column to the type of the field specified through the DataAlternateTextField property (System.String in the common case). You can also apply formatting using the DataAlternateTextFormatString property. 

[注意]注意

请注意,如果直接通过列的SortExpression属性指定排序表达式,则它将具有更高的优先级,并将覆盖DataAlternateTextField属性的排序/过滤条件。

该列的其他常用属性是AlternateText,ImageAlign,ImageWidth,ImageHeight等。以下示例显示了此产品在线演示中GridImageColumn的声明: CopyASPX

<telerik:GridImageColumn DataType="System.String" DataImageUrlFields="CustomerID"
  DataImageUrlFormatString="IMG/{0}.jpg" AlternateText="Customer image" DataAlternateTextField="ContactName"
  ImageAlign="Middle" ImageHeight="110px" ImageWidth="90px" HeaderText="Image Column"
  FooterText="ImageColumn footer">
</telerik:GridImageColumn>

答案 1 :(得分:0)

尝试在.aspx文件中实现类似的功能,看看它是怎么回事......

<telerikGridView:RadGridView.Columns>

 <telerikGridView:GridViewColumn UniqueName="img" Width="">

<telerikGridView:GridViewColumn.CellTemplate>
  <DataTemplate>
    <Image Stretch="None" Source="../Images/MyImage.png" /> // just an example path
  </DataTemplate>
  </telerikGridView:GridViewColumn.CellTemplate>

 </telerikGridView:GridViewColumn>

</telerikGridView:RadGridView.Columns>

答案 2 :(得分:0)

您可以尝试DataMemberBinding =&#34; {Binding [Image]}&#34;代替。