How can I bind "image1" to aspxImage?

52 Views Asked by At

I have a aspxImage but I can't give to datasource. I need to bind my "image1". You can take it from gridview or sqldatasource doesn't matter. How can I bind my image1 to aspxImage?

Here's my aspximage,gridview and my 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>
1

There are 1 best solutions below

0
Shahram Alemzadeh On

First change the aspximage to aspxbinaryimage and put it in a callback-panel:

    <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>

Then add a button (or link) to the gridview to send the id (or keyvalue) to the callback routine and get the image data from database:

<dx:GridViewDataColumn>
    <DataItemTemplate>
        <button type="button" onclick="cbp.PerformCallback('<%# Eval("id") %>'); popup.Show();">View Image</button>
    </DataItemTemplate>
</dx:GridViewDataColumn>

or

<dx:GridViewDataColumn>
    <DataItemTemplate>
        <button type="button" onclick="cbp.PerformCallback('<%# Container.KeyValue %>'); popup.Show();">View Image</button>
    </DataItemTemplate>
</dx:GridViewDataColumn>

In callback, retrieve the image-data from database and set it to the value of image in popup control:

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