Databinding for SSRS CustomReportItem
-
I am trying tie a reporting services data source with a custom report item and can't seem to find any helpful samples/documentation anywhere. This task is taking much longer than it should have at this point and I could really use some help if there's anyone who has done this before. What I want to do is create a series designer properties which allow me to : 1) select a data source from a list of available sources which have been defined for the report 2) select fields from the data source and assign them to designer properties 3) navigate the CustomReportItem.CustomData (is that the correct object?) object using the field names which were selected in step 2 (above) to retrieve the runtime values and bind them to my custom report item.
Mark's blog: developMENTALmadness.blogspot.com
-
I am trying tie a reporting services data source with a custom report item and can't seem to find any helpful samples/documentation anywhere. This task is taking much longer than it should have at this point and I could really use some help if there's anyone who has done this before. What I want to do is create a series designer properties which allow me to : 1) select a data source from a list of available sources which have been defined for the report 2) select fields from the data source and assign them to designer properties 3) navigate the CustomReportItem.CustomData (is that the correct object?) object using the field names which were selected in step 2 (above) to retrieve the runtime values and bind them to my custom report item.
Mark's blog: developMENTALmadness.blogspot.com
Well, I found the solution to the problem. The requirements for using the CustomData property are this: A) In the CustomReportItemDesigner class (your custom class which inherits from it as a base), override the InitializeNewComponent() method like this:
public override void InitializeNewComponent() { base.InitializeNewComponent(); CustomData = new CustomData(); //at least one grouping is required for both rows and columns //initialize a static row grouping CustomData.DataRowGroupings = new DataRowGroupings(); CustomData.DataRowGroupings.DataGroupings = new List<DataGrouping>(1); CustomData.DataRowGroupings.DataGroupings.Add(new DataGrouping()); CustomData.DataRowGroupings.DataGroupings[0].Static = true; // initialize a Static column grouping CustomData.DataColumnGroupings = new DataColumnGroupings(); CustomData.DataColumnGroupings.DataGroupings = new List<DataGrouping>(1); CustomData.DataColumnGroupings.DataGroupings.Add(new DataGrouping()); CustomData.DataColumnGroupings.DataGroupings[0].Static = true; //initialize data row with empty values for designer CustomData.DataRows = new List<DataRow>(1); CustomData.DataRows.Add(new DataRow()); CustomData.DataRows[0].Add(new DataCell()); //define the fields you will store (these will be populated with expressions by custom designer properties you define) CustomData.DataRows[0][0].Add(new DataValue("Label", String.Empty)); CustomData.DataRows[0][0].Add(new DataValue("X", String.Empty)); CustomData.DataRows[0][0].Add(new DataValue("Y", String.Empty)); }
B) Define custom designer properties to set the expressions for the DataValuesCollection (only showing one property here to keep things shorter)[Browsable(true), Category("Data")] public string XValue { get { if (CustomData.DataRows.Count > 0 && CustomData.DataRows[0].Count > 0) return GetDataValue(CustomData.DataRows[0][0], "X"); else return "X Coordinate"; } set { SetDataValue(CustomData.DataRows[0][0], "X", value); } } private string GetDataValue(DataCell cell, string name) { foreach (DataValue value in cell) if (value.Name == name) return value.Value; return null; } private void SetDataValue(DataCell cell, string name, string expression) { foreach (DataValue value in cell) if (value.Name == name) { value.Value = expression; return; } DataValue datavalue = new DataValue(name, expression); cell.Add(dat