Pages

Friday, July 9, 2010

Table of Content In RDLC

Introduction :
This article show you how you can create Table Of Content In rdlc report . I have written step to fetch page no of the rdlc page .

 Step 1.Go In Report >> Report Properties >> Code >>

Step 2. Write Following code in Code .

Public Function GetValue(PageNo As String) As String
Dim path As String = "Test"
Dim Sb As New System.Text.StringBuilder()
Try
If Not String.IsNullOrEmpty(PageNo.Trim().Split("-"C)(1).ToString()) Then
Dim con As String = "Connection String"
Dim Cn As New System.Data.SqlClient.SqlConnection(con)
Cn.Open()
Dim Cmd As New System.Data.SqlClient.SqlCommand("INSERT INTO DATA(NAME) VALUES('" & PageNo & "')", Cn)
Cmd.ExecuteNonQuery()
Cn.Close()
End If
Return path
Catch Exc As System.Exception
Return Exc.Message
End Try
End Function

Step 3. then add following assembly In references :

System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 

Step 4.Then In header of the report In textbox write

=code.GetValue(Globals!PageNumber & " -  " &  ReportItems!textbox8.Value   )

Step 5. Finally In code behind add Following Code Lines.

ReportViewer1.LocalReport.ExecuteReportInCurrentAppDomain(AppDomain.CurrentDomain.Evidence);
ReportViewer1.LocalReport.ExecuteReportInCurrentAppDomain(System.Reflection.Assembly.GetExecutingAssembly().Evidence);
ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
ReportViewer1.LocalReport.Refresh();

Page no of Page where textbox8 reside will be insert in database .In these way you can generate Table of Content .Generate One Doc File and merge it with exported Doc File .
 

Related Other posts

1 comment:

  1. This was exactly what I wanted and your instructions were easy to follow. In my case, I get two database entries each time I run the report -- the first entry always indicates page 1, while the second entry always indicates the correct page.

    Any ideas why the code is being executed twice, and why the page number is incorrect on the first call?

    In case it's relevant, I'm generating PDFs in the code-behind, so I believe the execution is triggered when I call ReportViewer1.LocalReport.Render(), which I've confirmed I am not calling twice.

    Thanks,
    Chris

    ReplyDelete