更改放置在网格模板列中的图像的图像URL

本文关键字:图像 URL 网格 | 更新日期: 2023-09-27 18:37:06

我正在尝试在网格视图中显示图像,但是,网格视图中显示的列都是动态显示的(未生成)。

我已经看过这篇文章,但它似乎不适用于我的情况:如何访问放置在网格视图中的项模板内的图像控件的 ImageUrl 属性

我有一个包含这些列的网格视图:

    <Columns> 
        <telerik:GridBoundColumn  HeaderText="Custom1"   HeaderStyle-VerticalAlign="Bottom" DataField="Custom1" SortExpression="Custom1"/>
        <telerik:GridDateTimeColumn HeaderText="Custom2"   HeaderStyle-VerticalAlign="Bottom" DataField="Custom2" SortExpression="Custom2"/>
        <telerik:GridCheckBoxColumn  HeaderText="Custom3"   HeaderStyle-VerticalAlign="Bottom" DataField="Custom3" SortExpression="Custom3"/>
        <telerik:GridTemplateColumn HeaderText="Custom4" HeaderStyle-VerticalAlign="Bottom" DataField="Custom4"><itemtemplate><asp:Image runat="server" ID="Custom4_pic"/></itemtemplate></telerik:GridTemplateColumn>

重复四列更改 Custom# 值,直到达到 48。

然后,我继续隐藏所有不必要的列,只显示我需要的列。(这是因为用户可以定义列的显示顺序,并且硬编码是我可以快速实现它的最简单的方法)。

一切都显示正常,但是,我似乎无法弄清楚如何为图像控件设置 ImageURL。 对于其余的专栏,这就是我的做法:

dt = new DataTable();
// Do some stuff...
if (aProperty.WebControlType == EntityPropertyWebControlType.CheckboxYN || aProperty.WebControlType == EntityPropertyWebControlType.OptionYN)
{
    dt.Columns.Add("Custom" + ((i * 4) - 1).ToString(), typeof(bool));
    break;
}
else if (aProperty.WebControlType == EntityPropertyWebControlType.Date)
{
    dt.Columns.Add("Custom" + ((i * 4) - 2).ToString(), typeof(DateTime));
    break;
}
else if (aProperty.WebControlType == EntityPropertyWebControlType.Image)
{
    // Not sure what to do here...
    break;
}
else
{
    dt.Columns.Add("Custom" + ((i*4) - 3).ToString(), typeof(string));
    break;
}
// Do more stuff...
// Based on type I will set the values to equal something.. so for example
dr["Custom" + aProperty.LabelColumnNo.ToString()] = "Text" or bool or DateTime
// However I'm not sure what to do for Image...
// and then I return the datatable to be binded to the gridview

任何提示都会很棒,谢谢!

更改放置在网格模板列中的图像的图像URL

我已经解决了这个问题。

我用 GridImageColumns 替换了模板列,然后在代码隐藏中,我将列添加到字符串类型的数据表中,然后使用图像处理程序,并将字符串设置为图像处理程序页。