none
"rdlc" add a column problem

    Question

  • I  build a Report.rdlc file and show correctly in ReportViewer control. Now , I want to add a column to the result view ,how can I do ?(I didn't want to create a new "rdlc" file)  ,thanks!

    Friday, August 10, 2007 7:21 AM

All replies

  • What is the problem you are having doing this?

     

    Did you create the original RDLC using the Wizard, is that it?

     

    Here are the general steps you need to follow:

     

    1. Open the RDLC in the Designer (doubleclick it in your Solution Explorer)
    2. You will need to adjust the data source you have bound to this report in your surrounding application code (since RDLCs accept the data, already processed, from the outside).  I can't tell you how to do this because I have no idea how you supply the data source in your application <s>.
    3. With the Report Designer having focus in Visual Studio, you should see a Report item on your Menu.  From that menu popup, choose to display Data Sources...
    4. You should be able to edit your DataSet definition for this report from there.
    5. In the Designer window, rightclick on a column in the table layout element.  You can Insert Column to the right or left of the one you selected, from the rightclick menu.

    Hope this helps,

     

    >L<

    Saturday, August 11, 2007 4:16 PM
  • Thanks,I had read you answer and known your meaning ,I should describe my problem detailedly.

    With the Designer,I had build a original RDLC and show correctly in the reportviewer control .

    Running the page the report include three columns("id" ,"name","age") and there is a button on the page.

    Now , I want to add a column("phone") to the report when I click the button, so I can't add a new column with the designer.

    Sorry! My English is poor , I hope you can understand my meaning.

     

     

    id             name                 age                                             id             name            age          phone

    1             Jim                     19                                               1               Jim              19            1234

    ...             ...                      ...                                                ...             ...                 ...             ...

    .                                                          =========》

    .                                                          click button

    .

    ...             ...                      ...                                                ...             ...                  ...             ...

    Monday, August 13, 2007 12:51 AM
  • So, the button is on your ASPX page?

     

    You could have the button set a parameter in the report and refresh the report.  The column would always be in the report but sometimes it would be visible and sometimes not, depending on the value of the parameter. 

     

    Would that work for you?

     

    If necessary, you could design a second report and the button would attach that report to the reportviewer localreport, instead of the original.  The second report would have the extra column.  But if all you really need is one extra column, I don't think you need to do this, simply hiding and showing the extra parameter should fulfill the requirement..

     

    >L<

    Monday, August 13, 2007 5:37 AM
  • Thanks Lisa Nicholls!

              I agree with you .  your method can achieve the effect. I know that the "rdlc" is a description file( XML file ) about report ,so that  I want to dynamic change the description file to achieve the effect.I think that changed the description file is a effective method.  Can you tell me how to do this?

     

    (My English is poor,I hope you can understand my words,thanks!)

     

    Monday, August 13, 2007 8:05 AM
  • (Your English is fine <s>)

     

    'You can easily change the RDLC file dynamically.  This is a good choice to make if you need to change to many different possible extra columns. 

     

    But it is not a good choice if you only want to add one column, and that column is always the same one.  If there are not many possibilities, it is better to have two RDLCs and just switch between them.

     

    Here is why I say that: If you want to change the RDLC file dynamically you still need to re-attach the viewer to the "new" version of the file, just as if it was a second report.  You won't avoid writing that code, you may just re-load from a stream (see below) rather than from a file <s>.

     

    If you decide you want to change the RDLC contents dynamically, rather than having two files, you can do it at least 2 ways:

     

    1) load the RDLC document up as a standard XML document and adjust it by adding information for the extra column.  If you want to do this, the best thing to do is to create two examples, one with the extra column and one without, and use one of many tools available to do an XML DIFF.  You may also want to take a look at the RDL/RDLC schema (XSD) which is available on-line.  (http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition/ReportDefinition.xsd I think is the right one) This  is a low-level approach, and you may want to take it if you are generally comfortable doing things with XML.

     

    2)  The high-level approach is more "RDL-centric".  You will find a tutorial that will help you here http://msdn2.microsoft.com/en-us/library/aa337451.aspx .  It does almost exactly what you want (update the report programmatically). It should not matter that this is an RDLC rather than an RDL for your purposes, except that you will not be doing the steps in the tutorial involving downloading the report from the server and loading it back to the server -- Lesson #4 in the tutorial is the important one, for you.  You will also find a slightly more complete example of dynamic RDL generation here: http://gotreportviewer.com/ -- look for the "Generate dynamically" samples on the bottom right of the page. 

     

    Either way, you will also need to look at the tutorial on "Supplying RDLs as streams" which you will find on the same site.

     

    Hope this helps,

     

    >L<

     

     

     

    Monday, August 13, 2007 2:54 PM
  • Thanks Lisa Nicholls !

             Thank you for the answer,I had read your answer detailedly and discoverded that the content of your answer exceed my knowledge. I need more study about XML  to understand your meaning. In addition, the link(http://gotreportviewer.com) is invalid. Now, I have no ability to validate your answer ,so I can't mark as answer.
    Sorry !  I will come back !

     

    Tuesday, August 14, 2007 1:23 AM
  • hi there,

     

    I don't much care if you mark my answer or not -- that's not why I'm "here" <s>.

     

    But http://gotreportviewer.com/ is definitely not invalid.  Please do visit that site and the documentation walkthroughs I mentioned -- I think they will help you.

     

    Regards,

     

    >L<

     

    Tuesday, August 14, 2007 4:03 PM
  •  

    Have you solve your Problem???. If yes Please Mail me as soon as possible. It's Urgent
    Thursday, April 17, 2008 10:13 AM
  •  

    Have you solve your Problem???.  Please tell me answer  as soon as possible. It's Urgent
    Thursday, April 17, 2008 10:14 AM
  • I don't see my last reply, so I'll duplicate here:

    I want to dynamically format fields in an .rdlc report, that's all.

    Example:

    I want to be able to hide or show a label and it's corresponding text field based on a user variable.
    I've got the whole user variable stuff figured out, and now just need to hide or show, or even strike through a label in the .rdlc at run time.

    How do I do that?

    I read some of the dynamic generation articles, but their parameters did not seem to work in my code. 

    I'm using Visual Basic Studio 2005.

    Daniel
    Thursday, November 06, 2008 3:53 PM
  • The visibility of a report item and the formatting of a textbox can all be set to an expression like =IIF(Parameters!UseRed.Value, "Red", "Black") and set the LocalReport.SetParameters method to pass the settings in.


    Nick Allen, Microsoft SQL Server Reporting Services. This posting is provided "AS IS" with no warranties and confers no rights.
    Saturday, November 08, 2008 4:58 AM
  • Thanks for the reply:

    I will bear this in mind when doing one field formatting in the future.

    Unfortunately, I need configuration based on ALL fields on the reports, and that would be tedious indeed to create a specific parameter to each field.
    In other words, the user can configure (via a special .ini file) specific data fields in SQL to be considered hidden.  On my form and via VBA.NET the controls and labels associated with the data field that's configured, are hidden, amongst other things.

    On the report, I'd need the same field and label to be hidden.  So if they configure 7 fields to be hidden, I'd need 7 parameters in the report object for each one, correct?

    paramater1 = datafield1Hidden
    parameter2 = datafield2Hidden

    etc....

    Which means, also that I'd need to create the parameters for EVERY field in the report, including the labels, because we don't know which data fields the user's going to want to hide.

    But it is a great plan for formatting single fields.

    Daniel
    Saturday, November 08, 2008 8:23 PM
  • The only other option is to create/modify the RDLC directly. You'll need to clarify what didn't work when you tried this previously. Also note that for RDLC you need to use the SQL Server Reporting Services 2005 RDL schema. If you plan on adding/removing the cloumns, I would suggest creating two RDLC files, one with a particular column and one without, and then looking at the difference with an XML diff tool. Also you could programatically change the "Hidden" value of the columns in the RDLC. You can programmatically change the formatting too. It's all just XML.
    Nick Allen, Microsoft SQL Server Reporting Services. This posting is provided "AS IS" with no warranties and confers no rights.
    Monday, November 10, 2008 10:22 PM
  • You don't need a separate parameter per field.

    I wrote a walkthrough for this... http://spacefold.com/lisa/post/2008/05/25/Walkthrough-A-Simple-ish-Runtime-Quick-Report.aspx

    >L<


    http://spacefold.com/lisa
    Tuesday, January 27, 2009 5:07 PM
  • Hi Lisa, 
    I have a simelar problem, I have a list item that recive a collection of objects that were made specificly for this report.
    the problem is i need the size and location of the textboxs to be decided according to the parameters defind on each object in the collection.
    ex' : i have:     String ValueForDisplay
    int Position   // enum value like : Top; NewRow; SameRow and so on
    Double Width
    Double Hieght
    now what I could not figure out is how to, in run time, set these values.
    I prefer not to dynamicly create a new rdlc file on each run but so far that is the only way I have found to do this.
    I'm using VS 2005, C#, .Net 2.0
    Thanks 
    Friday, June 26, 2009 9:36 AM
  • Hi there, UdiKafri,

    I think you are saying some or all of the following:

    1. you have report parameters indicating the "size and location" for certain specific classes of textboxes in the report.  ? 
    2. how does the list item send its information to the report?  Is there a matching parameter or parameters?  What do they look like?
    3. at runtime, you set the "size and location" of these classes. 
      * -- Can you confirm that by "size" you mean height, width, or both?
      * -- Can you confirm that by "location" you mean top, left, or both?
      * -- Does your int Position
    4. which classes of textboxes are affected by this? 
      * -- Are you in a repeating data region, or is this just free layout content, perhaps the page header?
      * -- is this code running for every textbox, or just a few?
      * -- if it is not running for every textbox, do the other items in the layout have to "make room" when you make these changes?
    5. Is StringValueForDisplay maybe the contents of the textbox that is affected by this collection, which sounds like it is only customizing the header?

    If this is not correct, can you make your example or scenario a bit clearer?  I'll do my best <s>.

    >L<

     


    http://spacefold.com/lisa
    Friday, June 26, 2009 9:50 PM
  • I'll try to clearify:
    I have an ArrayList of DataSourceObjects as data source for the whole report.
    each DataSourceObject has 2 types of properties
    1. Value related data (this is the contentent of the report) ex': Name, Phone num, Address and so on.
    2. Design related data (this is for position - left and top, color, width, height, font and so on)
    each DataSourceObject have diffrent values for the design that are set while creating them, when all DataSourceObjects are initialized they are set in to ArrayList and the ArrayList is sent to the reportViewer.
    here is my problem:
    I can't set some of the values to <expression> (fill in the desinger code to read my DataSourceObject.Top for exmple), nor change the xml (rdlc) 
    I can do it for font, color  but not for the "top", "Left", "Width", "height".
    I have to do it only in runtime because I don't know in advance how many items (for one object) and where they should be on the form.
    these items are in a data region type List, it run only on some properties some are staticly positioned but sometimes need to "move and make room" in the layout.

    I am not using any of the Global parameters of the report.
    All of my data is contained in these DataSourceObjects.
    In the report itself I use regular textbox from the designer.
    Header and Footer -- I have no problems with since they are totaly not used in this report.

    I hope i made my self clear and thanks for your help
    Udi
    Tuesday, July 07, 2009 12:52 PM
  • Hi again,

    I am sorry that I am slow to get to work on this.

    The more I think about it, the more I see resolutions that may or may not fit your situation depending on what is so special about your DataSourceObject and its attributes.

    Maybe the problem is that I rarely use object data sources for RS and therefore can't be sure there isn't some idea I'm missing.

    You say:

    >>I have to do it only in runtime because I don't know in advance how many items (for one object) and where they should be on the form.

    Are you saying you don't know which of the items in a list of items has the attributes?

    If so, can you clarify for me: in your List data region, is there one item or multiple items?  IOW, does your List data region repeat once for every instance of the object, or does it contain multiple instances of the object?

    I have a feeling -- which I can't prove yet, because I don't understand your data situation -- that you are trying to manage some things manually (such as height) that the report layout can manage for you, if you let it.

    Another question I have is about the font size and dimensions.  Do you need to change the Width and Height because
    you change font size on some instances, or is there another reason?

    Other things that you want to manage (such as width) do not necessarily make sense to me.  Is this why you want to manage the Left value on some objects because you changed the Width of another one in the same horizontal row?

    Do you need these various attributes only for the report, or have you created them to show the objects dynamjically on a web or win form? I am guessing this might be the case because you used the word "form".  You might be trying to replicate the web or win form in your printed report.  Could that be it?

    I *think* there might be a better way to do this, but without understanding the dynamic effect you are trying to achieve, and how important (or not) it is that the result exactly match another representation in your application, it is hard to guess.

    Another reason you might have used the word "form" is that you are designing an application where somebody lays out objects to match a printed form layout, and then the report actually prints the result on the paper form.  Could that be it?  Once again, I think there is a better way.

    FYI: If I can't figure out a way to do this kind of thing with demo data, so that the solution helps more than just one case, I usually have to ask the person with the question to send me something I can run without making a lot of effort to reconstruct the problem myself.  Maybe I could be clearer about all this if you e-mailed me a sample, or at least a serialized version of your objects.  If you are really using these attributes because they are displayed dynamically on a form, then maybe a screen shot of different instances of the form would help.

    The e-mail I use here is my real e-mail.  If it is obfuscated in the forum (I really don't remember) you'll also find it on my site, spacefold.com.

    >L<
    http://spacefold.com/lisa
    Sunday, July 12, 2009 1:59 AM
  • Hi Lisa,
    I can't send you any specific things because I'm not sure what and how much exactly but I think I can illustrate the problem we are trying to solve:
    we have schools as customers, every school sends an annual report to all students.
    this report is created based on the student courses, the type of education, the grades in each course, evaluation from the teacher of each course and a summery from the personal coach (there are a few more thing but it does not directly influence the creation of the report).
    Now, the problem for us is that the layout of the report depends on ALL of the present data - for example if a student have a FAILED grade it should not only get a color red(no problem using the expression in the report) but also the LEFT and TOP for the relevant fields that relate to it, and as result also the WIDTH and HEIGHT of fields.
    OR if some data is missing (some schools don't use it all) again the layout must change.
    we only know what layout the report should be AFTER the dataSourceObject was created with all relevant data.
    we than add it to a collection of  dataSourceObjects and update some global parameters for the collection.
    this collection has a function GetData() that returns 1 dataSourceObject and is used as the dataset for a list with in the report this equals 1 student report.
    in that way all relevant students are passed in the collection and for each of them a report with a different layout should be created.
    hope that simplified things.
    for now our working solution is having .rdlc file for each student BUT that is an expensive process because it means that we are creating a report per student and this is not what we prefer.
    hope I managed to clear things up.
    Thank you for your time.
    Udi
    Friday, July 17, 2009 8:10 AM
  • Yes, thank you.  I have definitely encountered dynamic needs like this before.  It is my contention that you are going about it the wrong way -- and that is why you are having a hard time solving the problem.  I promise I *will* respond to this with some illustrations in a blog post, as best I can.

    I would like you to contact me e-mail first, if you don't mind.  I have a question to ask and I am not sure you will want to give the answer in public.

    >L<
    http://spacefold.com/lisa
    Friday, July 17, 2009 10:59 PM
  • OK -- I've written a blog post to describe a way (or two) to approximate the setting of "top, left, width, height" for you.

    http://spacefold.com/lisa/post/2009/07/26/YAPS-about-Dynamic-Layouts.aspx

    ... as I say there, I don't think it's necessarily the right way.  In the examples that you e-mailed me there isn't that much variation possible, and I think that you could create some report logic that would examine parameters or other input (such as a one-row dataset with instructions) to come up with dynamic orders, and dynamic content for your different blocks.  But if you really want to change the dimensions and positions of your layout controls, you (sort of) can.

    >L<
    http://spacefold.com/lisa
    Monday, July 27, 2009 7:20 AM