" HeaderButtonType="TextButton" /> " H-6ren">
gpt4 book ai didi

c# - 如何从 C# 中的 byte[] 数组设置 BinaryImageColumnin RadGrid 的图像源?

转载 作者:太空宇宙 更新时间:2023-11-03 23:12:48 25 4
gpt4 key购买 nike

我有以下 ASP.NET:

<Columns>
<telerik:GridClientSelectColumn UniqueName="GridClientSelectColumn1" />
<telerik:GridBinaryImageColumn UniqueName="BinaryImageColumn" />
<telerik:GridBoundColumn DataField="PRODUCT_NAME" SortExpression="PRODUCT_NAME" HeaderText="<%$ Resources:Strings, ProductName %>" HeaderButtonType="TextButton" />
<telerik:GridBoundColumn DataField="STORE_NAME" SortExpression="STORE_NAME" HeaderText="<%$ Resources:Strings, Supplier %>" HeaderButtonType="TextButton" />
<telerik:GridBoundColumn DataField="PRODUCT_PRICE" SortExpression="PRODUCT_PRICE" HeaderText="<%$ Resources:Strings, UnitPrice %>" HeaderButtonType="TextButton" />
<telerik:GridBoundColumn DataField="PRODUCT_QUANTITY" SortExpression="PRODUCT_QUANTITY" HeaderText="<%$ Resources:Strings, Quantity %>" HeaderButtonType="TextButton" />
<telerik:GridBoundColumn DataField="TRANS_TOTAL" SortExpression="TRANS_TOTAL" HeaderText="<%$ Resources:Strings, TotalPrice %>" HeaderButtonType="TextButton" />
</Columns>

代码隐藏:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) {
SQLHelper a = new SQLHelper(SQLHelper.ConnectionStrings.KernelConnectionString);
DataTable newdt = DataHelper.GetProductAdditionalObjects(11);
for (int i = 0; i < newdt.Rows.Count; i++) {
if (int.Parse(newdt.Rows[i]["PROD_OBJECT_SPECS_ID"].ToString()) == 1) {
byte[] img = Converter.ObjectToByteArray(newdt.Rows[i]["OBJECT_BINARIES"]); //Convert Object to Byte Array
}
}
GridDataItem item = e.Item as GridDataItem;
if (item != null) {
(item["BinaryImageColumn"].Controls[0] as RadBinaryImage).DataValue = img;
}
}

问题是它给我一个错误:当前上下文中不存在名称“img”,尽管它是我想在本例中使用的字节数组

最佳答案

图像字节数组可以在 RadGrid 的 ItemDataBound 事件中处理。

<Columns>
<telerik:GridBinaryImageColumn UniqueName="BinaryImageColumn" />
<telerik:GridBoundColumn DataField="PRODUCT_NAME" SortExpression="PRODUCT_NAME" HeaderText="<%$ Resources:Strings, ProductName %>" HeaderButtonType="TextButton" />
</Columns>

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
GridDataItem item = e.Item as GridDataItem;
if(item != null)
{
(item["BinaryImageColumn"].Controls[0] as RadBinaryImage).DataValue = yourImgByteArray;
}
}

Each cell in a GridBinaryImageColumn contains an image streamed from a binary image source field (specified through the DataField property of the column). When used, this column will show a RadBinaryImage control in view mode and RadUpload or RadAsyncUpload in edit mode to upload an image. The type of upload is determined by the UploadControlType property. Additionally, you can persist the binary data when an item is opened for edit by setting the PersistBinaryDataOnEdit property to true. This will force the control to pass the old binary image to the data source so it could be persisted and not deleted.

可以在以下链接中找到更多详细信息。

http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/columns/column-types#gridbinaryimagecolumn

关于c# - 如何从 C# 中的 byte[] 数组设置 BinaryImageColumnin RadGrid 的图像源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38430946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com