Solved

How do I reference a particular row in a report's dataset.

Posted on 2010-09-21
11
3,149 Views
Last Modified: 2013-11-26
I'm looking for a way to display first and last entries in a report header, similar to a name range for a directory.  http://msdn.microsoft.com/en-us/library/ms251668%28VS.80%29.aspx list expressions that would allow this, but it only offers the absolute first and absolute last entries.  I'm trying to display the range for each page. (Ex: P1 A - E, P2 E - G, P3 H - MI, etc.)

I am using VB.NET through VS 2010 and an rdlc local report (not Crystal Reports).  I've tried referencing a function through the report object's expression, but got an 'not declared' error.  I've tried adding custom code to the report, as per http://msdn.microsoft.com/en-us/library/ms252130%28v=VS.80%29.aspx.  I can't manage to find a way to reference a specific row in the dataset from the report. (OpenForms(formname), frmFormName.DataTable, Dataset.Item() all give me the same 'not declared' error.)

Is there a way to generate the string I'm attempting either automatically or manually?  (If only manually, I can determine which records to use based on the page number.)
0
Comment
Question by:icegator2
  • 6
  • 4
11 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 33726953
I dont know the RDLC product.

In Crystal I would do this with formulas int he page header and footer.
The page header formula would save the value you need from the first record on the page.
The page footer formula wuld do the same for the record it has and then display the value you want.

mlmcc
0
 
LVL 5

Expert Comment

by:puffdaddy411
ID: 33727118
So you have a column that has something like A-Z in the rows and you are breaking this master datatable into sub tables or lists on different pages such as you listed (P1 A - E, P2 E - G, P3 H - MI)?
 
Have you tried to create your needed strings and pass them to your report as parameters?  For some of these specific needs, I ususally pass parameters because it is easier to generate the result in code rather than on the rdlc report.
0
 

Author Comment

by:icegator2
ID: 33727686
mlmcc:  There are 'First' and 'Last' expressions, but they are not page specific.  I can't access the dataset from the header or footer without using from a pre-defined set of expressions, so (Fields!Item.Value, 'Dataset') causes a build error instead of producing whatever happens to be the current dataset row. (i.e. first for page one and first for page twelve will be the same regardless of what actually prints on the page.)

puffdaddy411: I'm not breaking a master table into sub-tables.  Imagine if you printed a dictionary as a single report.  The entries are a continuous list, but at the top of each page, the entry range changes based on the page.
   Previously, I printed an odd page layout as a single report, followed by an even page layout as a single report, and so on.  The parameter 'NameRange' worked then, but it didn't allow me to duplex print the report.  I have since figured out how to control the layout for each page style in a single report.  Unfortunately, the parameter is no longer correct.  I tried to re-assign the parameter during 'QueryPageSettings', but I don't have access to the page number of the report.
   I toyed with the idea of using several 'NameRange' parameters, passing all the values to the report and controlling visibility via page number.  While I control records per page, I have no way of anticipating total pages, thus knowing how many parameters to put on the report.  This would probably mean adding an unrealistically large number of parameters and hoping the users never try to print more pages that that.
0
 
LVL 5

Expert Comment

by:puffdaddy411
ID: 33728623
Sorry for the confusion here but I'm trying to get the details.  I got your dictionary example.  What type of object(s) are you placing on your report to display this information from your dataset?
0
 

Author Comment

by:icegator2
ID: 33728862
In the header, I'm using a textbox.  In the body, a table.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Accepted Solution

by:
puffdaddy411 earned 500 total points
ID: 33729118
Ok I've found something and got it to work on a dummy report I just created.  If we were using the dictionary example, we would have the name of the "Object" to be defined in a column (or even simply the first letter of the item).  In this case we will use "Object" as the column name.  Its first value would be "Aardvark", right?  =D
 
Anyway, if our dictionary was in a table (default name of "table1") in the report body, use the following line to show the first item on the current page in your page header.
 

=First(ReportItems("Object").Value)
 
The same can be done for the last item.
 
 =Last(ReportItems("Object").Value)
 
The only problem I see is that I got an error when I tried to add references to two report items in the same textbox in the header.  That apparently is not allowed.  So you could do some formatting with 2-3 separate textboxes to get the result you want.  Make sense?
 
P1: Aardvark - Bat
OR
P1: A - B
0
 

Author Comment

by:icegator2
ID: 33729493
So close.  Those expressions work great.  For some reason, it works fine on page one, but on page two (last page in this case), it makes itself and almost everything else in the header (not all though) invisible.

Now that you've pointed me in the right direction, I'll keep tweaking this and see if I can fix it.

Thanks a lot.
0
 
LVL 5

Expert Comment

by:puffdaddy411
ID: 33730033
I'm not in front of my PC, but try to trim() it. It sounds like the textbox is auto sizing due to extra blanks or something.
0
 
LVL 5

Expert Comment

by:puffdaddy411
ID: 33735379
Did the Trim() work for you?  I tested my make-shift report and did not have the same issue even without the Trim().
0
 

Author Comment

by:icegator2
ID: 33735968
I had "CanGrow = False", so the "Trim()" wasn't necessary.  A partial solution was that when designing, I put the start and end entry textboxes in a rectangle, fit the rectangle to the size of the two boxes, then used the location property to move the rectangle.  This relocated the rectangle, but left the textboxes where they were relative to the report, not the rectangle (a weird quirk, to say the least).  When the report printed, it pushed the other headings below the textboxes and off the header, making it look as if everything disappeared.

I finally got it.  I was also referencing an odd page item for the heading on even pages and getting errors.  I actually figured this out while putting code in here.

Where did you find the "ReportItem()" expression?  I've been having trouble finding good resources for working with local reports.
OddPgHead.jpg
EvenPgHead.jpg
0
 
LVL 5

Expert Comment

by:puffdaddy411
ID: 33736715
icegator2,
 
To be honest, I found "ReportItems()" in a random thread about a completely different subject.  I then researched it on MSDN.
 
http://msdn.microsoft.com/en-us/library/ms251716(VS.80).aspx
 
I started playing with it and came up with what you needed.  The only resource, other than EE =D , is www.gotreportviewer.com.
 
Good Luck!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now