Using MicrosoftReportViewer with Web Forms programmatically
Posted
by user283897
on Stack Overflow
See other posts from Stack Overflow
or by user283897
Published on 2010-03-11T21:41:47Z
Indexed on
2010/03/11
21:44 UTC
Read the original article
Hit count: 234
ASP.NET
Hi, I'm repeating my question because the prior one under this topic was lost. Could you please help me? I want to use MicrosoftReportViewer for Web Forms so that the DataSource be set programmatically. There is some sample code on the Internet for Windows Forms but I haven't found anything for Web Forms. For example, here is some code I've tried to use. It gives no errors but nothing is displayed.
How should I modify the code to display a table in the ReportViewer?
Imports System.Data Imports Microsoft.Reporting.WebForms
Partial Class TestReportViewer Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
CreateReport()
End Sub
Sub CreateReport()
Dim dt As DataTable
Dim rpt As ReportDataSource
dt = New DataTable("Sample")
With dt
.Columns.Add("No", GetType(Integer))
.Columns.Add("Name")
.Rows.Add(1, "A1")
.Rows.Add(2, "A2")
.Rows.Add(3, "A3")
.Rows.Add(4, "A4")
.AcceptChanges()
End With
rpt = New ReportDataSource
rpt.DataMember = "Sample"
rpt.Value = dt
rpt.Name = "test"
With ReportViewer1
.LocalReport.DataSources.Add(rpt)
.DataBind()
.LocalReport.Refresh()
End With
End Sub
End Class
© Stack Overflow or respective owner