Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Workaround for a Dynamic HeaderTemplate in Repeater 1

Status
Not open for further replies.

sbushway

Programmer
Jan 27, 2003
58
0
0
US
Hi,

I've got a report to display, and the header part of the report contains dynamic data (as does the main section). It looks like this:



Code:
Report Title 
Dynamic Data Dynamic Data Dynamic Data 
************************************************** 
NAME     DOB      M/F 
John Doe 1/1/1970 M 
Jane Doe 2/2/1980 F 
Jack Doe 3/3/1975 M 
Jill Doe 4/4/1981 F

I know that HeaderTemplates can't contain bound data. So is there a way to produce the report by using a Repeater?

(BTW: The report starts over on a new page after every 30 names)

Thanks,
Suzanne
 
That'd be great if you wouldn't mind doing a conversion to VB!
 
Ok - tell me, how are you getting this dynamic data for your column headers? And I'll just code the whole thing for you.
 
From a stored procedure - not sure if you need to see it or not, but here it is ... it's ugly, so bear with me.

Code:
CREATE PROCEDURE SPSLS_NEASRpts 
(
     @nUIC char(5), 
     @nRptID char(9), 
     @nIsAdmin char(1), 
     @nAll char(1),
     @nParent char(1)
)

AS

DECLARE @vUIC char(5)
DECLARE @vRptID char(9)
DECLARE @vIsAdmin char(1)
DECLARE @vAll char(1)
DECLARE @vParent char(1)

SET @vUIC = @nUIC
SET @vRptID = @nRptID
SET @vIsAdmin = @nIsAdmin
SET @vAll  = @nAll
SET @vParent = @nParent

DECLARE @SQL varchar(8000)
SET @SQL = ''

SET @SQL = @SQL + ' SELECT DISTINCT '
SET @SQL = @SQL + ' R.rptid, R.rptdiary, R.rptuic, R.rptcycle, R.rptpg, R.rptdate, U.UIC, '
SET @SQL = @SQL + 'CASE WHEN EXISTS (SELECT * FROM orders.dbo.tbl_Addresses T '
SET @SQL = @SQL + 'WHERE (T.Parent_UIC =        U.UIC) and (T.Parent_UIC <> T.UIC)) '
SET @SQL = @SQL + 'THEN ''P'' '
SET @SQL = @SQL + 'ELSE '''' '
SET @SQL = @SQL + 'END AS PARENT, '
SET @SQL = @SQL + 'U.PLAD AS ShortTitle, '
SET @SQL = @SQL + 'CC.RAAUTH AS CC_RAAUTH, '
SET @SQL = @SQL + ' (UPPER(LEFT(DATENAME(MONTH,(LEFT(CC.EXAMDATE,2)+''/''+SUBSTRING(CC.EXAMDATE,3,2)+''/''+RIGHT(CC.EXAMDATE,2))),3))+'' ''+RIGHT(CC.EXAMDATE,2)) as CC_FSTMOPR,'
SET @SQL = @SQL + 'C.cycle, speedie_date1, diary_ctrl, uic_ctrl, ra_sort_code AS rsc, date_of_adv AS doa, epg, drate, nam, ssn, erate1, series, serial, '
SET @SQL = @SQL + 'brclgroup, brcl_prof, prate1, tir, pc, nec_grp_cde AS necg, pro_gain_dup AS pgd, puic, dspg, std_score AS ss, perfac1, '
SET @SQL = @SQL + 'perf_mark1, tir_factor1 AS tirf1, awards, pna_factor1 AS pnaf1, cc_pna_ss1 AS cps1, cc_pna_perf1 AS cpp1, cc_pna_sum AS cps, strik_cut, '
SET @SQL = @SQL + 'final_mult1 AS fm1, fm_cut1, erlyind, pc1_cyc+pc2_cyc+pc3_cyc+pc4_cyc+pc5_cyc AS prevcyc, '
SET @SQL = @SQL + 'pc1_pts+pc2_pts+pc3_pts+pc4_pts+pc5_pts AS prevpts, total_pna_cc1 AS tpc1, '
SET @SQL = @SQL + 'rs1+rs2+rs3+rs4+rs5+rs6+rs7+rs8+rs9+rs10+rs11+rs12+rs13+rs14+rs15+rs16+rs17+rs18+rs19+rs20 AS raw_score, '
SET @SQL = @SQL + 'perc1+perc2+perc3+perc4+perc5+perc6+perc7+perc8+perc9+perc10+perc11+perc12+perc13+perc14+perc15+perc16+perc17+perc18+perc19+perc20 AS persent, '
SET @SQL = @SQL + 'arate1, spec_grp_ind AS sgi, sipg, tas, dtis, school_code AS sc, cuic, speedie_type AS sdt, speedie_datime AS sdd, '
SET @SQL = @SQL + 'ovrall_pct AS oap, status AS st, status1 AS s1, status2 AS s2, status3 AS s3, status4 AS s4, status5 AS s5, status6 AS s6, YY '

SET @SQL = @SQL + 'FROM NEASRPTSINDEX            R '
SET @SQL = @SQL + 'JOIN orders.dbo.tbl_Addresses U ON ( R.rptuic = U.UIC        ) '
SET @SQL = @SQL + 'or ((''' + @vAll + '''= ''y''         ) and (''' + @vUIC + '''  = U.Parent_UIC)) '
SET @SQL = @SQL + 'RIGHT OUTER '
SET @SQL = @SQL + 'JOIN orders.dbo.cyclemaster  CC ON (  CC.CYCLE    = R.rptcycle  ) and '
SET @SQL = @SQL + '(((R.rptpg     = ''7''       ) and (CC.PAYGRADE = ''E7''      )) or '
SET @SQL = @SQL + '((R.rptpg     = ''_''       ) and '
SET @SQL = @SQL + '(CC.Cycle+CC.PAYGRADE IN (Select cycle+paygrade '
SET @SQL = @SQL + 'from orders.dbo.cyclemaster '
SET @SQL = @SQL + 'where (paygrade    <> ''E7'') and '
SET @SQL = @SQL + '(RESULTSVIEW <> (Select case ''' +  @vIsAdmin + ''' when ''Y'' '
SET @SQL = @SQL + 'then '''' '
SET @SQL = @SQL + 'else ''NV'' end)))))) '
SET @SQL = @SQL + 'LEFT OUTER '
SET @SQL = @SQL + 'JOIN NEASRPTS                 C ON (  C.cycle       = R.rptcycle  ) and '
SET @SQL = @SQL + '(  speedie_date1 = R.rptdate   ) and (  uic_ctrl      = U.UIC       ) and '
SET @SQL = @SQL + '(((epg    <> ''7''       ) and (epg        LIKE R.rptpg   )) or ((epg           = ''7''       ) and (R.RPTPG       = ''7''       ))) '
SET @SQL = @SQL + 'WHERE R.rptid =' + @vRptID
SET @SQL = @SQL + 'ORDER BY U.UIC '

--select (@SQL)
exec(@SQL)

GO

(Sorry about how ugly the SP is - I had to use dynamic SQL since I had a big problem with parameter sniffing. )

And the way I'm populating the repeater is like this (taken from the HTML of the .ASPX page of my app)

Code:
<asp:Repeater ID="rptRCA" runat="server">         
  <HeaderTemplate>
    <%#PrintRCAHeader(Eval("pc"), Eval("uic_ctrl"), Eval("brclgroup"), Eval("rptcycle"), Eval("fstmopr"), RunDate(Mid(Eval("rptdate"), 3, 2)), Eval(Mid(Eval("rptdate"), 3, 2) & " " & "20" & Eval(Mid(Eval("rptdate"), 1, 2))), Eval("doa"), Eval("diary_ctrl"))%>
  </HeaderTemplate>
            
  <ItemTemplate>
    <%#PrintRCA(Eval("pc"), Eval("uic_ctrl"), Eval("nam"), Eval("ssn"), Eval("prate1"), Eval("arate1"), Eval("brcl_prof"), Eval("sgi"), Eval("sc"), Eval("awards"), Eval("tas"), Eval("dtis"), Eval("sipg"), Eval("dspg"), Eval("tpc"), Eval("necg"), Eval("perf_mark"), Eval("erlyind"))%>            
  </ItemTemplate>
</asp:Repeater>

"PrintRCAHeader()" is the function that's giving me a headache since it never gets databound and there's dynamic data that I need to display in the header.

Thank you for your time - I really appreciate it.
 
Why aren't you using a DataGrid with this? Just curious :)
 
I'll get back with you in a few mins, lunch time, heh.
 
Well, I liked that I could format the Repeater any way I wanted ...

And with the repeater, I can set the style of the HTML tables that I'm outputting to "page-break-before:always" since I need to start a new page for each different report. And I'm not sure how to do that with a GridView.

 
Code:
<asp:Repeater ID="rptRCA" runat="server" OnDataBinding="rptRCA_OnDataBinding">         
          
  <ItemTemplate>
    <%#PrintRCA(Eval("pc"), Eval("uic_ctrl"), Eval("nam"), Eval("ssn"), Eval("prate1"), Eval("arate1"), Eval("brcl_prof"), Eval("sgi"), Eval("sc"), Eval("awards"), Eval("tas"), Eval("dtis"), Eval("sipg"), Eval("dspg"), Eval("tpc"), Eval("necg"), Eval("perf_mark"), Eval("erlyind"))%>            
  </ItemTemplate>
</asp:Repeater>

Make the DataSet you bind to your Repeater Module leve so it can be accessed in the rptRCA_OnDataBinding Event

Code:
Private Sub rptRCA_OnDataBinding(ByVal sender As Object, ByVal e As DataRepeaterItemEventArgs) 


If e.Item.ItemType = ListItemType.Header

   e.Item.Cells(0).Text = ds.Tables(0).Row(0)("pc") & ds.Tables(0).Row(0)("uic_ctrl") & ds.Tables(0).Row(0)("brclgroup") & ds.Tables(0).Row(0)("rptcycle") & ds.Tables(0).Row(0)("fstmopr") & RunDate(Mid(ds.Tables(0).Row(0)("rptdate"), 3, 2)) & Mid(ds.Tables(0).Row(0)("rptdate"), 3, 2) & " 20" & Mid(ds.Tables(0).Row(0)("rptdate"), 1, 2) & ds.Tables(0).Row(0)("doa") & ds.Tables(0).Row(0)("diary_ctrl")


End If

End Sub

if DataRepeaterItemEventArgs doesnt work, use System.EventArgs

Hope I got close here....
 
I'm just about to leave for the day, but I REALLY appreciate the time you took on this. I'll give it a shot first thing tomorrow morning.

Thanks again - have a great afternoon,
Suzanne
 
Hi Therese,

A few quick things ... You said
"Make the DataSet you bind to your Repeater Module leve so it can be accessed in the rptRCA_OnDataBinding Event"

Was "leve" a typo? That's one of the things I was wondering about - how to have the DataSet (or DataView in my case) accessible in the OnDataBinding Event. Right now, just to get started, I've created a global DataView that I reference in the ODB Event.

Also, I'm getting an error that says "Method Protected Sub rptRCA_OnDataBinding(Sender as Object, e as RepeaterItemEventArgs) does not have the same signature as delegate "Delegate Sub EventHandler(sender as Object, e as System.EventArgs)". I've tried using OnDataBinding and ItemDataBound and I get the same error.

Once I get that figured out, will I be calling PrintRCAHeader() from the OnDataBound event?

Thanks so much for your help,
Suzanne
 
module level, sorry a typo. I think I should have said to you "global" dataset. (sorry VB isn't my strongest language nor is all its terminology).

Change RepeaterItemEventArgs to System.EventArgs.

And yes, if PrintRCAHeader concatentates everything nice and pretty like you need it and returns a string, , that is where you call it (OnDataBinding).

 
Bummer ... I get an error that says "Item is not a member of System.EventArgs
 
Kay - I figured out a way to get the error to go away: In my HTML of my .ASPX page I have this:
Code:
<asp:Repeater ID="rptRCA" runat="server" OnDataBinding="rptRCA_OnItemDataBound">

And in my function on my codebehind page, I have this:
Code:
Private Sub rptRCA_DataBinding(ByVal sender As Object, ByVal e As DataRepeaterItemEventArgs) Handles rptRCA_ItemDataBound

Now my problem is that "If e.Item.ItemType = ListItemType.Header" is never True. Did I not set something up right to not have any of the rows classify as a Header?

Thank you,
Suzanne
 
Sorry - I usually work with DataGrids - bare with me.

Try Putting a Header Template tag in your repeater, but keeping it empty and see if the code hits ListItemType.Header = true
 
Great minds think alike - I thought the same thing, tried it and it worked!

My header's still not printing out, but I think it may be bugs in my logic. So while I'm not completely sure that what I tried will work, it's definitely a great start.

Thank you *very* much for your time. I truly appreciate it!
 
Actually - I have one more question ...

My PrintRCAHeader() function returns a string variable that contains the HTML for the header. Where I'm calling PrintRCAHeader() is just a Sub, so I can't return anything from it. If I change it to a function, such as
Code:
Protected Function rptRCA_DataBinding(ByVal sender As Object, ByVal e As DataRepeaterItemEventArgs) as String Handles rptRCA_ItemDataBound
I get an error saying that
"Protected Function rptRCA_DataBinding(ByVal sender As Object, ByVal e As DataRepeaterItemEventArgs) as String cannot handle Public Function rptRCA_DataBinding(ByVal sender As Object, ByVal e As DataRepeaterItemEventArgs) because they do not have the same signature"

How do I return the string that outputs the HTML of the header table?
 
change your Protected Function rpt_RCA_DataBinding to a Public Function and see.

Sorry, I'm not a VB expert, so I may nor may not be on the right track.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top