Sharepoint 2010 - GridView Web part with indicator, sparklines and drill through

Figure1: Final look of web part


Figure2: Web part configuration

Dynamically add sparkline field to gridview
ImageField imageField = new ImageField();
imageField.DataImageUrlField = column.ColumnName;
imageField.DataImageUrlFormatString = "http://www.ewbi.com/ewbi.develop/sparklines/spark.ashx?type=smooth&d={0}&height=20";
gridView.Columns.Add(imageField);

Dynamically add Indicator image field to gridview
ImageField imageField = new ImageField();
imageField.DataImageUrlField = column.ColumnName;
imageField.DataImageUrlFormatString = "/GetIndicatorImage.aspx?Indicator={0}";
gridView.Columns.Add(imageField);

Dynamically add Hyperlink field to gridview
HyperLinkField hyperLinkField = new HyperLinkField();
hyperLinkField.HeaderText = column.ColumnName;
hyperLinkField.DataTextField = column.ColumnName;
hyperLinkField.DataNavigateUrlFields = DataNavigateUrlFields;
hyperLinkField.DataNavigateUrlFormatString = DataNavigateUrlFormatString;
gridView.Columns.Add(hyperLinkField);

Dynamically add hidden field to gridview
foreach (DataColumn column in hiddenFields)
{
HyperLinkField hyperLinkField = new HyperLinkField();
hyperLinkField.HeaderText = column.ColumnName;
hyperLinkField.DataTextField = column.ColumnName;
gridView.Columns.Add(hyperLinkField);
hyperLinkField.Visible = false;
}
gridView.DataSource = dataTable;
gridView.DataBind();

Add web part page that returns image
protected void Page_Load(object sender, EventArgs e)
{
string indicatorStr = Request.QueryString["Indicator"];
string baseUrl = HttpContext.Current.Request.ApplicationPath;
if (!baseUrl.EndsWith("/")) baseUrl += "/";
string url = "/sites/BES/PublishingImages/right_arrow.gif";
if (!string.IsNullOrEmpty(indicatorStr))
{
Double indicator = Double.Parse(indicatorStr);
if (indicator > 1) url = "/sites/BES/PublishingImages/up_arrow.gif";

No comments:

Post a Comment