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.
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.