这是我的 aspximage、gridview 和我的 sqldatasource
<dx:ASPxPopupControl ID="popup" runat="server"
ClientInstanceName="popup"
Modal="true" HeaderText="Büyütülmüş CRQS Fotoğrafları" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="Middle">
<ContentCollection>
<dx:PopupControlContentControl>
<dx:ASPxImage ID="img" runat="server" ImageUrl='<%# Eval("image1")%>'></dx:ASPxImage>
</dx:PopupControlContentControl>
</ContentCollection>
</dx:ASPxPopupControl>
<dx:ASPxGridView ID="PhotoGrid" DataSourceID="PhotoDataSource" KeyFieldName="id" Width="100%" runat="server" Visible="false" >
<ClientSideEvents RowClick="onRowClick" />
<Columns>
<dx:GridViewDataTextColumn FieldName="id" Visible="False">
</dx:GridViewDataTextColumn>
<dx:GridViewCommandColumn ShowEditButton="true" />
<dx:GridViewDataBinaryImageColumn FieldName="image1" Caption="Resim 1">
<PropertiesBinaryImage ImageHeight="170px" ImageWidth="160px" >
<EditingSettings Enabled="true" />
</PropertiesBinaryImage>
</dx:GridViewDataBinaryImageColumn>
<dx:GridViewDataBinaryImageColumn FieldName="image2" Caption="Resim 2">
<PropertiesBinaryImage ImageHeight="170px" ImageWidth="160px">
<EditingSettings Enabled="true" />
</PropertiesBinaryImage>
</dx:GridViewDataBinaryImageColumn>
</Columns>
</dx:ASPxGridView>
<asp:SqlDataSource runat="server" ID="PhotoDataSource"
UpdateCommand="UPDATE CRQSGroupsT SET image1 = @image1, image2 = @image2 WHERE id = @id"
SelectCommand="Select id,image1,image2 from CRQSGroupsT where id=@id"
ConnectionString="<%$ ConnectionStrings:default %>">
<UpdateParameters>
<asp:Parameter Name="image1" DbType="Binary" />
<asp:Parameter Name="image2" DbType="Binary" />
<asp:Parameter Name="id" />
</UpdateParameters>
<SelectParameters>
<asp:Parameter Name="id" />
</SelectParameters>
</asp:SqlDataSource>
首先将 aspximage 更改为 aspxbinaryimage 并将其放入回调面板中:
<dx:ASPxPopupControl ID="popup" runat="server"
ClientInstanceName="popup"
Modal="true" HeaderText="Büyütülmüş CRQS Fotoğrafları" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="Middle">
<ContentCollection>
<dx:PopupControlContentControl>
<dx:ASPxCallbackPanel ID="cbp" ClientInstanceName="cbp" runat="server" OnCallback="cbp_Callback">
<PanelCollection>
<dx:PanelContent>
<dx:ASPxBinaryImage ID="img" runat="server">
</dx:ASPxBinaryImage>
</dx:PanelContent>
</PanelCollection>
</dx:ASPxCallbackPanel>
</dx:PopupControlContentControl>
</ContentCollection>
</dx:ASPxPopupControl>
然后向 gridview 添加一个按钮(或链接),将
id
(或 keyvalue
)发送到回调例程并从数据库获取图像数据:
<dx:GridViewDataColumn>
<DataItemTemplate>
<button type="button" onclick="cbp.PerformCallback('<%# Eval("id") %>'); popup.Show();">View Image</button>
</DataItemTemplate>
</dx:GridViewDataColumn>
或
<dx:GridViewDataColumn>
<DataItemTemplate>
<button type="button" onclick="cbp.PerformCallback('<%# Container.KeyValue %>'); popup.Show();">View Image</button>
</DataItemTemplate>
</dx:GridViewDataColumn>
在回调中,从数据库中检索图像数据并将其设置为弹出控件中图像的
value
:
Protected Sub cbp_Callback(sender As Object, e As DevExpress.Web.CallbackEventArgsBase) Handles cbp.Callback
Using Connection As New SqlConnectionection("...")
Connection.Open()
Using Command As New SqlCommand("Select image1 from CRQSGroupsT where id=@id", Connection)
Command.Parameters.Add("@id", sqlDbType:=SqlDbType.Int).Value = CInt(e.Parameter)
img.Value = CType(Command.ExecuteScalar, Byte())
End Using
End Using
End Sub