This is a migrated thread and some comments may be shown as answers.

Binary Image not show in grid template

5 Answers 107 Views
BinaryImage
This is a migrated thread and some comments may be shown as answers.
Do Xuan
Top achievements
Rank 1
Do Xuan asked on 14 Oct 2014, 06:05 AM
I want to binding binaryimage from sql server.But it is not show. 

My Insert code
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
    {
        GridEditFormInsertItem insertItem = e.Item as GridEditFormInsertItem;
        string name = (insertItem["Name"].FindControl("txbName") as RadTextBox).Text;
        string Cate= (insertItem["IDCate"].FindControl("cboCate") as DropDownList).SelectedValue;
        RadAsyncUpload radAsyncUpload = insertItem["Pic"].FindControl("AsyncUpload1") as RadAsyncUpload;
 
        UploadedFile file = radAsyncUpload.UploadedFiles[0];
        byte[] pic= new byte[file.InputStream.Length];
        file.InputStream.Read(hinh, 0, (int)file.InputStream.Length);
        //file.InputStream.re
        //string hinh = con.ImageToByteArray(b);CONVERT(varbinary(30), @nvarcharParam)
        con.ExecuteSQL("INSERT INTO Hinh(IDCate, Name, Pic) VALUES(" + Cate+ ", N'" + name + "',CONVERT(varbinary(50),'" + pic + "'))");
    }

ASPX file
<telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" ShowStatusBar="True" GridLines="None"
             PageSize="3"
            OnNeedDataSource="RadGrid1_NeedDataSource" OnInsertCommand="RadGrid1_InsertCommand">
            <PagerStyle Mode="NumericPages" AlwaysVisible="true"></PagerStyle>
            <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="ID">
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton">
                        <HeaderStyle Width="36px"></HeaderStyle>
                    </telerik:GridEditCommandColumn>
                    <telerik:GridTemplateColumn HeaderText="ID" UniqueName="ID" SortExpression="ID" Visible="false">
                        <ItemTemplate>                           
                        </ItemTemplate>
                        <EditItemTemplate>                           
                        </EditItemTemplate>
                        <HeaderStyle Width="30%"></HeaderStyle>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Name" UniqueName="Name" SortExpression="Name">
                        <ItemTemplate>
                            <asp:Label runat="server" ID="lblName" Text='<%# Eval("Name") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadTextBox runat="server" Width="200px" ID="txbName" Text='<%# Eval("Name") %>'>
                            </telerik:RadTextBox>
                            <asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" ControlToValidate="txbName"
                                ErrorMessage="Please, enter a name!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                        <HeaderStyle Width="30%"></HeaderStyle>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Cate" UniqueName="IDCate" DataField="IDCate" >
                        <ItemTemplate>
                            <asp:Label runat="server" ID="lblCate" Text='<%# Eval("CateName") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate
                            <asp:DropDownList ID="cboCate" runat="server"  Width="200px" DataTextField="Cate" DataValueField="IDCate" DataSource="<%# loadCate() %>" SelectedValue='<%#  Bind("IDCate") %>'  AppendDataBoundItems="True" >
                            <asp:ListItem Selected="True" Text="Select" Value="">
                            </asp:ListItem>
                            </asp:DropDownList>                               
                        </EditItemTemplate>
                        <ItemStyle VerticalAlign="Top"></ItemStyle>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn DataField="Pic" HeaderText="Pic" UniqueName="Pic">
                        <ItemTemplate>
                            <telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" DataValue='<%#  Eval("Pic") %>'
                                AutoAdjustImageControlSize="false" Height="80px" Width="80px" ToolTip='<%#Eval("Pic", "Photo of {0}") %>'
                                AlternateText='<%#Eval("Pic", "Photo of {0}") %>'></telerik:RadBinaryImage>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadAsyncUpload runat="server" ID="AsyncUpload1" OnClientFileUploaded="OnClientFileUploaded"
                                AllowedFileExtensions="jpg,jpeg,png,gif" MaxFileSize="1048576" OnFileUploaded="AsyncUpload1_FileUploaded">
                            </telerik:RadAsyncUpload>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton">
                        <HeaderStyle Width="36px"></HeaderStyle>
                    </telerik:GridButtonColumn>
                </Columns>
                <EditFormSettings>
                    <EditColumn ButtonType="ImageButton">
                    </EditColumn>
                </EditFormSettings>
                <PagerStyle AlwaysVisible="True"></PagerStyle>
            </MasterTableView>
        </telerik:RadGrid>

And my table 
ID : int
IDCate: int
Name: nvarchar(50)
Pic: image (I try varbinary, text but it's not working)

P/S sorry for my english.

5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 17 Oct 2014, 06:11 AM
Hi,

In the demo below the BinaryImage in the Template column displays without problems. The data type is also image as it is in your case. I noticed that the code is also the same as in the demo, therefore it is strange that the image does not display:
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandradasyncupload/defaultcs.aspx?product=grid

If the problem still persists open a support ticket and send us a sample project where the issue can be observed.

Regards,
Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Do Xuan
Top achievements
Rank 1
answered on 22 Oct 2014, 07:13 AM
Thanks Pavlina,
I'm using your demo in my code, but it's not working. I thinks I have a problem when I save file in webresourece.axd. Please help me fix on my demo.
please download it from 4shared.com. sorry for the inconvenience.
http://www.4shared.com/zip/leGAaYQtba/ASYNUPBINARY.html 
0
Pavlina
Telerik team
answered on 24 Oct 2014, 03:27 PM
Hi,

I downloaded and ran the provided project but the grid is empty with no data? Should I make any changes?

Regards,
Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Do Xuan
Top achievements
Rank 1
answered on 25 Oct 2014, 05:25 AM
Hi,
You need to change connection string in ConnectionDB file (App_code). Thanks!!!
0
Do Xuan
Top achievements
Rank 1
answered on 27 Oct 2014, 09:36 AM
Hi Pavlina.
I have changed the way insert the data. Using sql parameters
        cmd.Parameters.Add("@Data", SqlDbType.Image);            
        cmd.Parameters["@Name"].Value = imageName;
And it's work.
again sincerely thank
Tags
BinaryImage
Asked by
Do Xuan
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Do Xuan
Top achievements
Rank 1
Share this question
or