Summary:
A GridView control on my consumer web part is breaking my web part
connection when changing the provided value. Any help in finding
the fix to this would be greatly appreciated.
Detail:
I am developing a web part connection to act as an employee filter.
The provider web part shows a list of employee names in a radio
button list control. The selected name is passed as the provided
value. The consumer web part uses the provided name to produce a
report specific to that name. The report is displayed on the
consumer web part as a GridView bound to a DataTable containing the
report data.
My problem is this. Once I add the bound GridView to the web part's
controls using the overridden CreateChildControls() method, any
change to the selected employee name on the provider web part causes
the newly selected name to not be passed to/received by the consumer
web part. The consumer filter is blank instead of containing the
value of the selected name. If I comment out the line that adds the
GridView control, the selected name passes/is received properly.
Any thoughts on why my GridView is breaking my web part connection?
====== Begin Provider Web Part Code ======
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Net;
using System.Web.UI.WebControls;
using System.Xml;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using ASPWebParts = System.Web.UI.WebControls.WebParts;
using SPWebParts = Microsoft.SharePoint.WebPartPages;
namespace My.SharePoint.WPProviders
{
public class EmployeeProvider : ASPWebParts.WebPart,
SPWebParts.ITransformableFilterValues
{
private RadioButtonList _rblEmployees = new RadioButtonList();
//
// Provider Connection
//
[ASPWebParts.ConnectionProvider
("Employees", "UniqueIDForEmployeesConnection",
AllowsMultipleConnections = false)]
public SPWebParts.ITransformableFilterValues SetConnection()
{
return this;
}
public bool AllowAllValue { get { return false; } }
public bool AllowEmptyValue { get { return false; } }
public bool AllowMultipleValues { get { return false; } }
public string ParameterName { get { return "Employee Name"; } }
public virtual ReadOnlyCollection<string> ParameterValues
{
get
{
EnsureChildControls();
List<string> employees = new List<string>();
employees.Add(_rblEmployees.SelectedValue);
ReadOnlyCollection<string> result = new
ReadOnlyCollection<string>(employees);
return result;
}
}
//
// Code to populate _rblEmployees not shown since it is working.
//
}
====== End Provider Web Part Code ======
====== Begin Consumer Web Part Code ======
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using ASPWebParts = System.Web.UI.WebControls.WebParts;
using SPWebParts = Microsoft.SharePoint.WebPartPages;
namespace My.SharePoint.WPConsumers
{
public class DataViewer : ASPWebParts.WebPart
{
private GridView _gv = new GridView();
protected override void CreateChildControls()
{
base.CreateChildControls();
//
// Consumer Connection
//
private List<SPWebParts.IFilterValues> _Filters = new
List<SPWebParts.IFilterValues>();
protected List<SPWebParts.IFilterValues> ConsumerFilters { get
{ return _Filters; } }
[ASPWebParts.ConnectionConsumer
("Employees", "UniqueIDForEmployeesConnection",
AllowsMultipleConnections = false)]
public void SetConnectionInterface(SPWebParts.IFilterValues
filter)
{
this.ConsumerFilters.Add(filter);
if (filter != null)
{
List<SPWebParts.ConsumerParameter> param = new
List<SPWebParts.ConsumerParameter>();
param.Add(new SPWebParts.ConsumerParameter("Employee
Name",
SPWebParts.ConsumerParameterCapabilities.SupportsMultipleValues |
SPWebParts.ConsumerParameterCapabilities.SupportsAllValue));
filter.SetConsumerParameters(new
ReadOnlyCollection<SPWebParts.ConsumerParameter>(param));
}
}
//
// Show the content of the consumer filters.
//
string strFilters = "";
foreach (SPWebParts.IFilterValues filter in ConsumerFilters)
{
foreach (string value in filter.ParameterValues)
if (!string.IsNullOrEmpty(value))
{
if (strFilters.Length > 0)
strFilters += "; ";
strFilters += filter.ParameterName + " = " + value;
}
}
DisplayMessage("Consumer Filters: " + strFilters);
//
// Define a simple DataTable: one column, one row.
// I've simplified the report data for this discussion.
//
DataTable dt = new DataTable();
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "Message";
dt.Columns.Add(column);
DataRow row = dt.NewRow();
row["Message"] = "No data to report.";
dt.Rows.Add(row);
//
// Define the GridView to display the report.
//
_gv = new GridView();
_gv.AutoGenerateColumns = true;
_gv.CellPadding = 3;
_gv.GridLines = GridLines.Horizontal;
_gv.AlternatingRowStyle.BackColor =
System.Drawing.Color.WhiteSmoke;
_gv.HeaderStyle.BackColor = System.Drawing.Color.LightGray;
_gv.Visible = true;
// Bind the GridView to the DataTable.
_gv.DataSource = dtEmpty;
_gv.DataBind();
// Add the GridView control.
Controls.Add(_gv);
}
}
}
====== End Consumer Web Part Code ======