Guest User

Guest User

  • Tech Writer
  • 14
  • 3.9k

bind the image from sharepoint picture library in Gridview

Jul 14 2014 11:40 AM
I have a picture library in my share Point 2010 site. I want to add these images in gridview column. so, I created one visual webpart in visual studio and I deployed the solution I am getting all other columns except this images.
 
I used the code like this:
 

Html code:

<asp:GridView ID="gvPictureLibrary" AutoGenerateColumns ="False" 

    runat="server" EnableModelValidation="True">

</asp:GridView>

 

 

Code-behind:

protected void Page_Load(object sender, EventArgs e)

        {

            if (!IsPostBack)

            {

                SPWeb site = SPContext.Current.Web;

                SPList list = site.Lists["PL"];

 

                DataTable dt = new DataTable();

                dt.Columns.Add("ImageUrl", typeof(string));

                DataRow dr;

                foreach (SPListItem item in list.Items)

                {

                    dr = dt.Rows.Add ();

                    dr["ImageUrl"] = item["ows_EncodedAbsThumbnailUrl"].ToString();

                }

                ImageField colImage = new ImageField();

                colImage.DataImageUrlField = "ImageUrl";

                colImage.HeaderText = "Image";

                gvPictureLibrary.Columns.Add(colImage);

                gvPictureLibrary.DataSource = dt;

                gvPictureLibrary.DataBind();

            }

        }

 
 
Please help me.
 
Thanks in Advance

Answers (2)