This is a migrated thread and some comments may be shown as answers.

Dynamically include TextBox?

6 Answers 540 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Will
Top achievements
Rank 1
Will asked on 05 Sep 2007, 03:51 PM
Hello -
I have a report which includes a couple of items that might not always appear on the report.  The user can select whether to include them on my web page interface.  When I run the report with all textboxes and data fields, it works fine.  But when the user selects to NOT include a couple of the fields, (this is handled via a stored procedure) the report errors out with something like:  The expression contains object 'Description' that is not defined in the current context.

Is there a way for me to dynamically add/remove the textbox control at runtime? 

Thanks
 - will

6 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 06 Sep 2007, 07:37 AM
Hello Will,

There are two approaches to that task:

You can create separate reports for the different combinations of user choices and then show the corresponding report.

--OR--

You can always pass all data to the report. Then, just before showing the report, you can make all items that do not need to show invisible. You can pass information regarding which items should be invisible as a parameter to the report's constructor and then based on that information hide the items after the InitializeComponent method call:

if (/*your logic here*/)
{
    this.textBox1.Visible = false;
    //...  
}

When a report item is data-bound with an item binding expression, it always expects that there will be such a column in the data source, and that is why you are getting the exception.

Best wishes,
Rossen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Will
Top achievements
Rank 1
answered on 06 Sep 2007, 07:47 AM
I had considered the idea of multiple reports....one for each combination of user choices, but abandoned that because I might end up having to create 5 or 6 reports.  It isn't a bad idea, but difficult to manage.

For the moment, I ended up just changing the SELECT statement in my Stored Proc to select NULL as the missing column names.  This seems to work fine. 

I'll take a look at your second suggestion.  But that makes me wonder about something else.  Is it possible to pass some sort of variable from the web page that hosts the report viewer control to the report itself?  This relates a little to another post....but I figured that I need to use the ItemDataBound event and I can set the value of a text box control, but I need it to be from something a user does on the web page.  Is this possible to achieve?  I thought about having to add a text box control in my web page's code-behind....but I am not sure how to do that.

thanks for any help
 - will
0
Chavdar
Telerik team
answered on 06 Sep 2007, 09:51 AM
Hi Will,

You can find some information about what you need in the following forum thread: How to create Web report w/parameter. The WinForms demo can be seen from here.

 
Sincerely yours,
Chavdar
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Will
Top achievements
Rank 1
answered on 06 Sep 2007, 02:30 PM
Thanks for the help!
0
Justin
Top achievements
Rank 2
answered on 25 Feb 2008, 04:05 PM
I'm attempting to do something similar..  On the detail_ItemDataBound event (which happens after InitializeComponent) in the report, I'm trying to remove a header textbox if the field is left blank in the bound dataset.

private void detail_ItemDataBound(object sender, System.EventArgs e)
{
  if (sender is Telerik.Reporting.Processing.DetailSection)
  {
       DataRowView drvDataItem = (sender as Telerik.Reporting.Processing.DetailSection).DataItem as DataRowView;

       // formats null values to "" and trims
       String checkVal = FormatNullValue(drvDataItem["togglefield"])
       if (checkVal.Length <= 0)
       { 
            this.textBox12.visible = false;
  }
}

That didn't remove/hide it, so I even tried:
this.Items["groupHeaderSection1"].Items.RemoveByKey("textBox12");

Neither approach worked.  Am I missing something?
0
Hrisi
Telerik team
answered on 25 Feb 2008, 06:00 PM
Hi Justin,

I think the following help article will be of help in your case: Using Section Events. In your code snippet you use the DetailSection instance from Telerik.Reporting.Processing namespace as expected, but this.textBox12 is referenced to the report definition item. You can get reference to the item from Telerik.Reporting.Processing namespace as described in the help:

Processing.DetailSection section = sender as Processing.DetailSection;
Processing.ReportItemBase textBox = section Items.Find("textBox12", false)[0];
textBox.Visible = false;


Sincerely yours,
Hrisi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
Will
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Will
Top achievements
Rank 1
Chavdar
Telerik team
Justin
Top achievements
Rank 2
Hrisi
Telerik team
Share this question
or