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

Cannot see the image using radgridview using linq

3 Answers 64 Views
BinaryImage
This is a migrated thread and some comments may be shown as answers.
shyam k
Top achievements
Rank 1
shyam k asked on 25 Jan 2010, 02:31 PM
Hi, 

 I am trying to use the gridbinary image in radgridview using linq. But its not displaying.
It works fine with the sql datasource but when i use linq no image is displayed.

Can any one suggest me how to write the code using linq for displaying the  image in radgridview

 

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" ClientEvents-OnRequestStart="conditionalPostback">

 

 

 

<telerik:RadProgressManager ID="RadProgressManager1" runat="server" />

 

 

 

<telerik:RadProgressArea ID="RadProgressArea1" runat="server" />

 

 

 

<telerik:RadGrid runat="server" ID="RadGrid1" onneeddatasource="RadGrid1_NeedDataSource" AllowPaging="True" AllowSorting="True"

 

 

 

AutoGenerateColumns="False" Width="97%" AllowAutomaticInserts="true"

 

 

 

AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" ShowStatusBar="True"

 

 

 

GridLines="None" OnItemDataBound="RadGrid1_ItemDataBound" OnItemCreated="RadGrid1_ItemCreated" PageSize="3">

 

 

 

<PagerStyle Mode="NumericPages" AlwaysVisible="true" />

 

 

 

<MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="ImageID" >

 

 

 

<Columns>

 

 

 

<telerik:GridEditCommandColumn ButtonType="ImageButton">

 

 

 

<HeaderStyle Width="3%" />

 

 

 

</telerik:GridEditCommandColumn>

 

 

 

<telerik:GridTemplateColumn HeaderText="ImageName" UniqueName="ImageName" SortExpression="ImageName">

 

 

 

<ItemTemplate>

 

 

 

<asp:Label runat="server" ID="lblName" Text='<%# Eval("ImageTitle") %>' />

 

 

 

</ItemTemplate>

 

 

 

<EditItemTemplate>

 

 

 

<telerik:RadTextBox runat="server" Width="200px" ID="txbImageTitle" Text='<%# Bind("ImageTitle") %>' />

 

<

 

 

asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" ControlToValidate="txbImageTitle"

 

 

ErrorMessage

 

="Please, enter a ImageTitle!" Display="Dynamic" SetFocusOnError="true" />

 

 

 

</EditItemTemplate>

 

 

 

<HeaderStyle Width="30%" />

 

 

 

</telerik:GridTemplateColumn>

 

 

 

<telerik:GridTemplateColumn HeaderText="ImageDescription" UniqueName="ImageDescription" DataField="ImageDescription">

 

 

 

<ItemTemplate>

 

 

 

<asp:Label ID="lblDescription" runat="server" Text='<%# TrimDescription(Eval("ImageDescription") as string) %>' />

 

 

 

</ItemTemplate>

 

 

 

<EditItemTemplate>

 

 

 

<telerik:RadTextBox ID="txbDescription" Width="300px" runat="server" TextMode="MultiLine"

 

 

 

Text='<%# Bind("ImageDescription") %>' Height="150px" />

 

 

 

</EditItemTemplate>

 

 

 

<ItemStyle VerticalAlign="Top" />

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

 

 

 

 

 

 

<telerik:GridBinaryImageColumn DataField="ImageFile" HeaderText="Image" UniqueName="Upload" ImageAlign="NotSet"

 

 

 

ImageHeight="80px" ImageWidth="80px" ResizeMode="Fit" DataAlternateTextField="ImageDescription"

 

 

 

DataAlternateTextFormatString="Image of {0}" >

 

 

 

<HeaderStyle Width="10%" />

 

 

 

 

</telerik:GridBinaryImageColumn>

 

 

 

 

<telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton">

 

 

 

<HeaderStyle Width="2%" />

 

 

 

</telerik:GridButtonColumn>

 

 

 

</Columns>

 

 

 

<EditFormSettings>

 

 

 

<EditColumn ButtonType="ImageButton" />

 

 

 

</EditFormSettings>

 

 

 

</MasterTableView>

 

 

 

</telerik:RadGrid>

 

 

 

</telerik:RadAjaxPanel>


.cs file

 

 

public void BindGrid()

 

{

 

 

 

// RadGrid1.DataSource = PR.ListAllImages();

 

 

 

 

 

 

 

int ImagTemp = Convert.ToInt32(Request.QueryString["TemplateID"]);

 

 

 

// RadGrid1.DataSource = PR.GetImageGalleryDetailByTemplateID(ImagTemp);

 

 

 

 

 

RadGrid1.MasterTableView.DataSource = PR.GetImageGalleryDetailByTemplateID(ImagTemp);

 

}

 

 

protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)

 

{

BindGrid();

 

}

 

 

 

//code added for edit update and delete data

 

 

 

 

 

 

 

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

 

{

 

 

if (e.Item is GridEditableItem && e.Item.IsInEditMode)

 

{

 

 

GridBinaryImageColumnEditor editor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("Upload") as GridBinaryImageColumnEditor;

 

RadAjaxPanel1.ResponseScripts.Add(

 

string.Format("window['UploadId'] = '{0}';", editor.RadUploadControl.ClientID ));

 

}

}

 

 

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)

 

{

 

 

if (e.Item is GridEditableItem && e.Item.IsInEditMode)

 

{

 

 

GridBinaryImageColumnEditor editor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("Upload") as GridBinaryImageColumnEditor;

 

 

 

TableCell cell = (TableCell)editor.RadUploadControl.Parent;

 

 

 

CustomValidator validator = new CustomValidator();

 

validator.ErrorMessage =

 

"Please select file to be uploaded";

 

validator.ClientValidationFunction =

 

"validateRadUpload";

 

validator.Display =

 

ValidatorDisplay.Dynamic;

 

cell.Controls.Add(validator);

}

}

 

 

 

protected string TrimDescription(string description)

 

{

 

 

if (!string.IsNullOrEmpty(description) && description.Length > 200)

 

{

 

 

return string.Concat(description.Substring(0, 200), "...");

 

}

 

 

return description;

 

}

 

 

// end of code

 

 

 

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 28 Jan 2010, 04:26 PM
Hello shyam,

Can you verify that you are returning a correct binary image data as byte array from you enitty's ImageFile property?

All the best,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
shyam k
Top achievements
Rank 1
answered on 28 Jan 2010, 05:34 PM
Hi  Rosen,
   I debugged the application and it is returning the binary image as byte array but it is not displaying...
0
Rosen
Telerik team
answered on 02 Feb 2010, 08:22 AM
Hi shyam,

Can you please post both of your webconfig's handlers sections?

Best wishes,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
BinaryImage
Asked by
shyam k
Top achievements
Rank 1
Answers by
Rosen
Telerik team
shyam k
Top achievements
Rank 1
Share this question
or