0
我想在gridview中顯示圖像,但是,在gridview中顯示的列全部是動態顯示的(不是生成的)。更改ImageURL放置在GridTemplateColumn中的圖像
我已經看過這個帖子了,但它似乎並沒有在我的情況下工作: How to access ImageUrl property of the Image Control placed inside a ItemTemplate in the GridView
我有與這些列的GridView:
<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>
四列重複更改自定義#值直到它達到48.
然後我繼續隱藏所有不必要的列,只顯示我需要的列(這是因爲用戶可以定義要排列的列的順序r,並且對它進行硬編碼是我可以快速實現的最簡單的方法)。
一切正常顯示,但是,我似乎無法計算如何設置圖像控件的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
任何提示將是偉大的,謝謝!