Dynamically include TextBox?

7 posts, 0 answers
  1. Will
    Will avatar
    45 posts
    Member since:
    Aug 2007

    Posted 05 Sep 2007 Link to this post

    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
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 06 Sep 2007 Link to this post

    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
  3. DevCraft banner
  4. Will
    Will avatar
    45 posts
    Member since:
    Aug 2007

    Posted 06 Sep 2007 Link to this post

    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
  5. Chavdar
    Admin
    Chavdar avatar
    898 posts

    Posted 06 Sep 2007 Link to this post

    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
  6. Will
    Will avatar
    45 posts
    Member since:
    Aug 2007

    Posted 06 Sep 2007 Link to this post

    Thanks for the help!
  7. Justin
    Justin avatar
    16 posts
    Member since:
    Oct 2007

    Posted 25 Feb 2008 Link to this post

    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?
  8. Hrisi
    Admin
    Hrisi avatar
    221 posts

    Posted 25 Feb 2008 Link to this post

    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
Back to Top
DevCraft banner