For my application I need to build report parameters programmatically. I have tried to follow the examples available but I cannot get the parameters to display as a dropdown list of values. The parameter does show up in the viewer but as a textbox. Below is the code that I am using to build my parameter -
| Dim vals As New ArrayList |
| <fill vals with strings of option values> |
| Dim param As New ReportParameter |
| param.Type = ReportParameterType.String |
| param.UI.Visible = True |
| param.UI.MultiValue = True |
| param.Value = vals |
| Me.ReportParameters.Add(param) |
This is wrapped in a routine that is called when the report is bound to it's data source. When I try to call the routine from the report's constructor it results in a run-time error.
My questions are:
1. How do I get my options to show up as a dropdown list?
2. When should this routine be called?
3. Is it possible to build it with a value/key pair rather than just a list of values?
----------------------------------------------------------------------------------------------------------------
Upon further investigation, either programmatic definition of parameters is not supported or the documentation is severely lacking because I have tried every example (there are just a few) that I can find and it either results in no parameter or a run-time error. For example, just trying to add a simple test parameter with the following code results in no parameter in the viewer:
| Public Sub New() |
| InitializeComponent() |
| ReportParameters.Add("Test", ReportParameterType.String, "test") |
| End Sub |
Thanks,
Dave
| private void MyTable_NeedDataSource(object sender, EventArgs e) |
| { |
| SqlCommand sqlSelectCommand = new SqlCommand |
| { |
| CommandText = "SP_MyStoredProc", |
| Connection = new SqlConnection {ConnectionString = ConnectionString}, |
| CommandType = CommandType.StoredProcedure |
| }; |
| sqlSelectCommand.Parameters.Add("@individualId", SqlDbType.Int); |
| sqlSelectCommand.Parameters["@individualId"].Value = txtIndividualId.Value; //This is incorrect |
| Telerik.Reporting.Processing.Table tbl = (Telerik.Reporting.Processing.Table)sender; |
| tbl.DataSource = new SqlDataAdapter { SelectCommand = sqlSelectCommand }; |
| } |
Hi,
I want to print the telerik report from command line instead of using the
Print icon provided on Reportviewer toolbar. Please let me know if it is possible to
print telerik report from command line.
Thank you,
Anita.
| foreach (string filterRow in showHide) |
| { |
| switch(filterRow) |
| { |
| case "10": |
| this.textBoxEventTotals.Visible = true; |
| this.subReportCommunityEventTotals.Visible = true; |
| this.subReportCommunityEventTotals.Report.Visible = true; |
| break; |
| case "20": |
| this.textBoxEventTotalsByDate.Visible = true; |
| this.subReportCommunityEventTotalsByDate.Visible = true; |
| this.subReportCommunityEventTotalsByDate.Report.Visible = true; |
| break; |
| case "30": |
| this.textBoxTotalsByCommunity.Visible = true; |
| this.subReportCommunityEventTotalsByCommunity.Visible = true; |
| this.subReportCommunityEventTotalsByCommunity.Report.Visible = true; |
| break; |
| case "40": |
| this.textBoxCommunityAndDate.Visible = true; |
| this.subReportCommunityEventsByCommunityAndDate.Visible = true; |
| this.subReportCommunityEventsByCommunityAndDate.Report.Visible = true; |
| break; |
| case "50": |
| this.textBoxDetails.Visible = true; |
| this.subReportCommunityEventDetails.Visible = true; |
| this.subReportCommunityEventDetails.Report.Visible = true; |
| break; |
| } |
| } |
| } |
namespace
ClassLibrary1
{
using System;
using System.Data;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Telerik.Reporting;
using Telerik.Reporting.Drawing;
/// <summary>
/// Summary description for Report1.
/// </summary>
public partial class Report1 : Telerik.Reporting.Report
{
public string constr;
public Report1(string cnstr)
{
/// <summary>
/// Required for telerik Reporting designer support
/// </summary>
InitializeComponent();
System.Data.OleDb.
OleDbConnection cn = new System.Data.OleDb.OleDbConnection();
System.Data.OleDb.
OleDbCommand cmd = new System.Data.OleDb.OleDbCommand();
System.Data.OleDb.
OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter();
DataTable dt = new DataTable();
cn.ConnectionString = cnstr;
constr = cnstr;
cmd.CommandText =
"Select * from company";
cmd.Connection = cn;
da.SelectCommand = cmd;
da =
new System.Data.OleDb.OleDbDataAdapter("Select * from company", cnstr);
this.DataSource = da;
}
private void Report1_NeedDataSource(object sender, System.EventArgs e)
{
string sql =
@"Select * from company";
//da.SelectCommand = new System.Data.OleDb.OleDbCommand(sql);
System.Data.OleDb.
OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter(sql,constr);
DataSet dataSet = new DataSet();
da.Fill(dataSet);
(sender
as Telerik.Reporting.Processing.Report).DataSource = dataSet;
}
private void textBox2_ItemDataBound(object sender, EventArgs e)
{
Telerik.Reporting.Processing.
TextBox txtPosition = (Telerik.Reporting.Processing.TextBox)sender;
if (txtPosition.Text.Contains("Developer"))
{
txtPosition.Style.BackgroundColor =
Color.Blue;
}
}
}
}
this is how designer code looks :
namespace
ClassLibrary1
{
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Telerik.Reporting;
using Telerik.Reporting.Drawing;
partial class Report1
{
#region
Component Designer generated code
/// <summary>
/// Required method for telerik Reporting designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
Telerik.Reporting.Drawing.
StyleRule styleRule1 = new Telerik.Reporting.Drawing.StyleRule();
Telerik.Reporting.Drawing.
StyleRule styleRule2 = new Telerik.Reporting.Drawing.StyleRule();
Telerik.Reporting.Drawing.
StyleRule styleRule3 = new Telerik.Reporting.Drawing.StyleRule();
Telerik.Reporting.Drawing.
StyleRule styleRule4 = new Telerik.Reporting.Drawing.StyleRule();
this.dataSet = new ClassLibrary1.DataSet();
this.labelsGroupHeader = new Telerik.Reporting.GroupHeaderSection();
this.labelsGroupFooter = new Telerik.Reporting.GroupFooterSection();
this.labelsGroup = new Telerik.Reporting.Group();
this.pageHeader = new Telerik.Reporting.PageHeaderSection();
this.reportNameTextBox = new Telerik.Reporting.TextBox();
this.pageFooter = new Telerik.Reporting.PageFooterSection();
this.currentTimeTextBox = new Telerik.Reporting.TextBox();
this.pageInfoTextBox = new Telerik.Reporting.TextBox();
this.reportHeader = new Telerik.Reporting.ReportHeaderSection();
this.titleTextBox = new Telerik.Reporting.TextBox();
this.detail = new Telerik.Reporting.DetailSection();
this.dataSetTableAdapter1 = new ClassLibrary1.DataSetTableAdapters.DataSetTableAdapter();
this.textBox1 = new Telerik.Reporting.TextBox();
((System.ComponentModel.
ISupportInitialize)(this.dataSet)).BeginInit();
((System.ComponentModel.
ISupportInitialize)(this)).BeginInit();
//
// dataSet
//
this.dataSet.DataSetName = "DataSet";
this.dataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
//
// labelsGroupHeader
//
this.labelsGroupHeader.Height = new Telerik.Reporting.Drawing.Unit(0.28125, Telerik.Reporting.Drawing.UnitType.Inch);
this.labelsGroupHeader.Name = "labelsGroupHeader";
this.labelsGroupHeader.PrintOnEveryPage = true;
//
// labelsGroupFooter
//
this.labelsGroupFooter.Height = new Telerik.Reporting.Drawing.Unit(0.28125, Telerik.Reporting.Drawing.UnitType.Inch);
this.labelsGroupFooter.Name = "labelsGroupFooter";
this.labelsGroupFooter.Style.Visible = false;
//
// labelsGroup
//
this.labelsGroup.Bookmark = null;
this.labelsGroup.GroupFooter = this.labelsGroupFooter;
this.labelsGroup.GroupHeader = this.labelsGroupHeader;
//
// pageHeader
//
this.pageHeader.Height = new Telerik.Reporting.Drawing.Unit(0.28125, Telerik.Reporting.Drawing.UnitType.Inch);
this.pageHeader.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
this.reportNameTextBox});
this.pageHeader.Name = "pageHeader";
//
// reportNameTextBox
//
this.reportNameTextBox.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(0.02083333395421505, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505, Telerik.Reporting.Drawing.UnitType.Inch));
this.reportNameTextBox.Name = "reportNameTextBox";
this.reportNameTextBox.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(6.4166665077209473, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224, Telerik.Reporting.Drawing.UnitType.Inch));
this.reportNameTextBox.StyleName = "PageInfo";
this.reportNameTextBox.Value = "Report1";
//
// pageFooter
//
this.pageFooter.Height = new Telerik.Reporting.Drawing.Unit(0.28125, Telerik.Reporting.Drawing.UnitType.Inch);
this.pageFooter.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
this.currentTimeTextBox,
this.pageInfoTextBox});
this.pageFooter.Name = "pageFooter";
//
// currentTimeTextBox
//
this.currentTimeTextBox.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(0.02083333395421505, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505, Telerik.Reporting.Drawing.UnitType.Inch));
this.currentTimeTextBox.Name = "currentTimeTextBox";
this.currentTimeTextBox.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(3.1979167461395264, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224, Telerik.Reporting.Drawing.UnitType.Inch));
this.currentTimeTextBox.StyleName = "PageInfo";
this.currentTimeTextBox.Value = "=NOW()";
//
// pageInfoTextBox
//
this.pageInfoTextBox.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(3.2395832538604736, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505, Telerik.Reporting.Drawing.UnitType.Inch));
this.pageInfoTextBox.Name = "pageInfoTextBox";
this.pageInfoTextBox.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(3.1979167461395264, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224, Telerik.Reporting.Drawing.UnitType.Inch));
this.pageInfoTextBox.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Right;
this.pageInfoTextBox.StyleName = "PageInfo";
this.pageInfoTextBox.Value = "=PageNumber";
//
// reportHeader
//
this.reportHeader.Height = new Telerik.Reporting.Drawing.Unit(0.80823493003845215, Telerik.Reporting.Drawing.UnitType.Inch);
this.reportHeader.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
this.titleTextBox});
this.reportHeader.Name = "reportHeader";
//
// titleTextBox
//
this.titleTextBox.Name = "titleTextBox";
this.titleTextBox.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(6.4583334922790527, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.78740161657333374, Telerik.Reporting.Drawing.UnitType.Inch));
this.titleTextBox.StyleName = "Title";
this.titleTextBox.Value = "Report1";
//
// detail
//
this.detail.Height = new Telerik.Reporting.Drawing.Unit(0.28125, Telerik.Reporting.Drawing.UnitType.Inch);
this.detail.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
this.textBox1});
this.detail.Name = "detail";
//
// dataSetTableAdapter1
//
this.dataSetTableAdapter1.ClearBeforeFill = true;
//
// textBox1
//
this.textBox1.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(0.19999997317790985, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.081210456788539886, Telerik.Reporting.Drawing.UnitType.Inch));
this.textBox1.Name = "textBox1";
this.textBox1.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(1.9000000953674316, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000012218952179, Telerik.Reporting.Drawing.UnitType.Inch));
this.textBox1.Value = "[=Fields.[Company Name]]";
//
// Report1
//
this.Groups.AddRange(new Telerik.Reporting.Group[] {
this.labelsGroup});
this.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
this.labelsGroupHeader,
this.labelsGroupFooter,
this.pageHeader,
this.pageFooter,
this.reportHeader,
this.detail});
this.PageSettings.Landscape = false;
this.PageSettings.Margins.Bottom = new Telerik.Reporting.Drawing.Unit(1, Telerik.Reporting.Drawing.UnitType.Inch);
this.PageSettings.Margins.Left = new Telerik.Reporting.Drawing.Unit(1, Telerik.Reporting.Drawing.UnitType.Inch);
this.PageSettings.Margins.Right = new Telerik.Reporting.Drawing.Unit(1, Telerik.Reporting.Drawing.UnitType.Inch);
this.PageSettings.Margins.Top = new Telerik.Reporting.Drawing.Unit(1, Telerik.Reporting.Drawing.UnitType.Inch);
this.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.Letter;
this.Style.BackgroundColor = System.Drawing.Color.White;
styleRule1.Selectors.AddRange(
new Telerik.Reporting.Drawing.ISelector[] {
new Telerik.Reporting.Drawing.StyleSelector("Title")});
styleRule1.Style.Color = System.Drawing.
Color.Black;
styleRule1.Style.Font.Bold =
true;
styleRule1.Style.Font.Italic =
false;
styleRule1.Style.Font.Name =
"Tahoma";
styleRule1.Style.Font.Size =
new Telerik.Reporting.Drawing.Unit(20, Telerik.Reporting.Drawing.UnitType.Point);
styleRule1.Style.Font.Strikeout =
false;
styleRule1.Style.Font.Underline =
false;
styleRule2.Selectors.AddRange(
new Telerik.Reporting.Drawing.ISelector[] {
new Telerik.Reporting.Drawing.StyleSelector("Caption")});
styleRule2.Style.Color = System.Drawing.
Color.Black;
styleRule2.Style.Font.Name =
"Tahoma";
styleRule2.Style.Font.Size =
new Telerik.Reporting.Drawing.Unit(11, Telerik.Reporting.Drawing.UnitType.Point);
styleRule2.Style.VerticalAlign = Telerik.Reporting.Drawing.
VerticalAlign.Middle;
styleRule3.Selectors.AddRange(
new Telerik.Reporting.Drawing.ISelector[] {
new Telerik.Reporting.Drawing.StyleSelector("Data")});
styleRule3.Style.Font.Name =
"Tahoma";
styleRule3.Style.Font.Size =
new Telerik.Reporting.Drawing.Unit(11, Telerik.Reporting.Drawing.UnitType.Point);
styleRule3.Style.VerticalAlign = Telerik.Reporting.Drawing.
VerticalAlign.Middle;
styleRule4.Selectors.AddRange(
new Telerik.Reporting.Drawing.ISelector[] {
new Telerik.Reporting.Drawing.StyleSelector("PageInfo")});
styleRule4.Style.Font.Name =
"Tahoma";
styleRule4.Style.Font.Size =
new Telerik.Reporting.Drawing.Unit(11, Telerik.Reporting.Drawing.UnitType.Point);
styleRule4.Style.VerticalAlign = Telerik.Reporting.Drawing.
VerticalAlign.Middle;
this.StyleSheet.AddRange(new Telerik.Reporting.Drawing.StyleRule[] {
styleRule1,
styleRule2,
styleRule3,
styleRule4});
this.Width = new Telerik.Reporting.Drawing.Unit(6.4583334922790527, Telerik.Reporting.Drawing.UnitType.Inch);
((System.ComponentModel.
ISupportInitialize)(this.dataSet)).EndInit();
((System.ComponentModel.
ISupportInitialize)(this)).EndInit();
}
#endregion
private GroupHeaderSection labelsGroupHeader;
private GroupFooterSection labelsGroupFooter;
private Group labelsGroup;
private PageHeaderSection pageHeader;
private Telerik.Reporting.TextBox reportNameTextBox;
private PageFooterSection pageFooter;
private Telerik.Reporting.TextBox currentTimeTextBox;
private Telerik.Reporting.TextBox pageInfoTextBox;
private ReportHeaderSection reportHeader;
private Telerik.Reporting.TextBox titleTextBox;
private DetailSection detail;
private DataSet dataSet;
private ClassLibrary1.DataSetTableAdapters.DataSetTableAdapter dataSetTableAdapter1;
private Telerik.Reporting.TextBox textBox1;
}
}
now when i try to use this class from webreport viewer :
ClassLibrary1.
Report1 rpt = new ClassLibrary1.Report1(cn.ConnectionString);
rpt.constr = cn.ConnectionString;
ReportViewer1.Report = rpt;
Viewer shows this twice :