- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
" HeaderButtonType="TextButton" /> " H-6ren">
我有以下 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.
可以在以下链接中找到更多详细信息。
关于c# - 如何从 C# 中的 byte[] 数组设置 BinaryImageColumnin RadGrid 的图像源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38430946/
我有以下 ASP.NET: " HeaderButtonType="TextButton" /> " HeaderButtonType="TextButton" /> " H
我是一名优秀的程序员,十分优秀!