+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to display image inside my GridView in my .ascx control

How to display image inside my GridView in my .ascx control

2 posts, 0 answered
  1. test
    test avatar
    4 posts
    Registered:
    24 Jun 2016
    31 Aug
    Link to this post

    Hi everyone,

    I have a problem displaying image inside gridview in ascx control.

    I used <asp:ImageField DataImageUrlField="???" HeaderText="Image"></asp:ImageField> , is this the correct way? and  I don't know the DataImageUrlField   fill with.

    As addition, is <asp:GridView a good way to list my custom content in sitefinity?

    Regards,

    Eddy

     

     

    My code:

    .ascx file used in widget:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="wucSupplier2.ascx.cs" Inherits="SitefinityWebApp.wucSupplier2" %>

    <asp:GridView ID="GridView1" runat="server"  AutoGenerateColumns="False">
        <Columns>
            <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
            <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
            <asp:ImageField DataImageUrlField="???" HeaderText="Image"></asp:ImageField>
        </Columns>
    </asp:GridView>

     

     

    .cs file

    using System;
    using System.Linq;
    using System.Collections.Generic;
    using Telerik.Sitefinity.Model;
    using Telerik.Sitefinity.DynamicModules;
    using Telerik.Sitefinity.Data.Linq.Dynamic;
    using Telerik.Sitefinity.DynamicModules.Model;
    using Telerik.Sitefinity.Utilities.TypeConverters;
    using Telerik.Sitefinity.GenericContent.Model;

    namespace SitefinityWebApp
    {
        public partial class wucSupplier2 : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                // Fetch a collection of "live" and "visible" supplier items.
                var myCollection = GetDataItems();

                // Binds the collection of Person items to the RadGrid
                GridView1.DataSource = myCollection;
                GridView1.DataBind();
            }

            // Gets a collection of "live" and "visible" supplier items.
            public IQueryable<DynamicContent> GetDataItems()
            {
                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
                Type supplierType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.SBC.Supplier");

                // Fetch a collection of "live" and "visible" supplier items.
                var myCollection = dynamicModuleManager.GetDataItems(supplierType)
                    .Where(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && i.Visible == true);

                return myCollection;
            }
        }
    }

  2. test
    test avatar
    4 posts
    Registered:
    24 Jun 2016
    06 Sep in reply to test
    Link to this post

    Hello everyone,

    I checked in the table that the dynamic module created, seems there is no field indicating the image data is kept,  do i need something like join table to get the image data to be binded in my gridview?

    Does anyone can help me?

     

    Regards,

    Eddy

2 posts, 0 answered