I want to binding binaryimage from sql server.But it is not show.
My Insert code
ASPX file
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.
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.