using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Linq;
using System.Linq;
using Microsoft.SharePoint.Linq.Rules;
namespace ImagesProgram.ImagesProgram
{
[ToolboxItemAttribute(false)]
public class ImagesProgram : WebPart
{
SPGridView sgvImages;
protected override void Render(HtmlTextWriter writer)
{
try
{
sgvImages.RenderControl(writer); |
catch (Exception ex)
{
writer.Write(ex.ToString());
}
}
protected override void CreateChildControls()
{
try
{
string Title = string.Empty;
string Status = string.Empty;
LinqSampleDataContext context = new LinqSampleDataContext(SPContext.Current.Web.Url);
var query = from cs in context.SharePoint2010Concepts
where cs.Status.Title.ToString() != "Completed"
orderby cs.Id descending
select new
{
Title = cs.Title,
Status = cs.Status.Title,
};
sgvImages = new SPGridView();
sgvImages.AutoGenerateColumns = false;
sgvImages.RowDataBound += new GridViewRowEventHandler(sgvImages_RowDataBound);
this.Controls.Add(sgvImages);
BoundField bTitle = new BoundField();
bTitle.HeaderText = "Task Name";
bTitle.DataField = "Title";
sgvImages.Columns.Add(bTitle);
BoundField bToolTip = new BoundField();
bToolTip.HeaderText = "Status";
bToolTip.DataField = "Status";
sgvImages.Columns.Add(bToolTip);
ImageField IStatus = new ImageField();
IStatus.HeaderText = "Status";
IStatus.ControlStyle.CssClass = "ImageCss";
IStatus.DataImageUrlField = "Status";
IStatus.DataImageUrlFormatString = SPContext.Current.Web.Url + "/UserPages/Images/{0}.jpg";
sgvImages.Columns.Add(IStatus);
sgvImages.DataSource = query;
sgvImages.DataBind();
}
catch (Exception ex)
{
this.Controls.Add(new LiteralControl(ex.ToString()));
}
}
void sgvImages_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[2].ToolTip = e.Row.Cells[1].Text;
}
e.Row.Cells[1].Visible = false;
}
catch (Exception ex)
{
this.Controls.Add(new LiteralControl(ex.ToString()));
}
}
}
}
No comments:
Post a Comment