I may seem dumb but this has had me going around in circles.
The report sits on the Report Server and requires ONE parameter "GROUPNAME". my code gives me a cast error when I try to set the parameters.
Please help:
Imports Microsoft.Reporting.webforms
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ReportParameter(0)
ReportViewerMain.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
ReportViewerMain.ServerReport.ReportServerUrl = New Uri("http://localhost/ReportServer")
ReportViewerMain.ServerReport.ReportPath = "/RptTest/RptTestParm"
ReportViewerMain.ShowParameterPrompts = True
ReportViewerMain.ShowPrintButton = True
Dim rptParameters As New ReportParameter(1)
rptParameters = New ReportParameter("GROUPNAME", "Adm01")
ReportViewerMain.ServerReport.SetParameters(rptParameters)
ReportViewerMain.ZoomPercent = 100
ReportViewerMain.ServerReport.Refresh()
End Sub
End Class
This is my code so far.
Thanks
Mac
your problem lies in your code itself
you have not properly instantiated the reportparameter array
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ReportParameter(0)
ReportViewerMain.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
ReportViewerMain.ServerReport.ReportServerUrl = New Uri("http://localhost/ReportServer")
ReportViewerMain.ServerReport.ReportPath = "/RptTest/RptTestParm"
ReportViewerMain.ShowParameterPrompts = True
ReportViewerMain.ShowPrintButton = True
Dim rptParameters As New ReportParameter(1)
RptParameters(0) = New ReportParameter("GROUPNAME", "Adm01")
ReportViewerMain.ServerReport.SetParameters(rptParameters)
ReportViewerMain.ZoomPercent = 100
ReportViewerMain.ServerReport.Refresh()
End Sub
you have not instantiated the array for the report parameters properly
thanks
Related
asp.net (with vb.net) control array at run time giving error :
Object reference not set to an instance of an object.
I am getting this error.
My Code is :
Partial Class _Default
Inherits System.Web.UI.Page
Dim chk(10) As CheckBox
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
Else
MsgBox("loading")
chk(0) = New CheckBox
With chk(0)
.ID = "chk(0)"
.Text = .ID
End With
Me.form1.Controls.Add(chk(0))
End If
TextBox1.Text = chk(0).Text
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If chk(0).Checked = True Then
MsgBox("Yes")
Else
MsgBox("No")
End If
Response.Redirect("Page1.aspx")
End Sub
End Class
Use this instead:
Dim chk As CheckBox
chk = New CheckBox
Solved !
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
Else
MsgBox("loading")
chk(0) = New CheckBox
With chk(0)
.ID = "chk(0)"
.Text = .ID
End With
Me.form1.Controls.Add(chk(0))
End If
TextBox1.Text = chk(0).Text
End Sub
How to create a class or some other stuff to make all the DataGridView inside my project of same format i:e AlternativeRowColor, ForColor,BackColor and Other properties. Currently i have to go to each of the control property to set , it sucks when user requested to change and property of Grid as i have to change in all the DataGridView.
Public Class FrmArticle
Private Sub GridFormatting(ByVal DGV As DataGridView)
DGV.ForeColor = Color.Black
DGV.BackgroundColor = Color.AliceBlue
DGV.AlternatingRowsDefaultCellStyle.BackColor = Color.Brown
DGV.AlternatingRowsDefaultCellStyle.ForeColor = Color.DodgerBlue
DGV.ColumnHeadersDefaultCellStyle.ForeColor = Color.CadetBlue
DGV.ColumnHeadersDefaultCellStyle.BackColor = Color.DarkGoldenrod
DGV.EnableHeadersVisualStyles = False
End Sub
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GridFormatting(DataGridView1)
End Sub
End Class
or
Module GridFormat
Public Sub GridFormatting(ByVal DGV As DataGridView)
DGV.ForeColor = Color.Black
DGV.BackgroundColor = Color.AliceBlue
DGV.AlternatingRowsDefaultCellStyle.BackColor = Color.Brown
DGV.AlternatingRowsDefaultCellStyle.ForeColor = Color.DodgerBlue
DGV.ColumnHeadersDefaultCellStyle.ForeColor = Color.CadetBlue
DGV.ColumnHeadersDefaultCellStyle.BackColor = Color.DarkGoldenrod
DGV.EnableHeadersVisualStyles = False
End Sub
End Module
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GridFormatting(DataGridView1)
End Sub
I have a vb.net asp application where I'm loading a control (from another control on a page). I want to set a variable between the two controls when it loads.
This is where I load the control:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim AuditControl As Control = LoadControl("~/controls/auditcompanies.ascx")
phCompanies.Controls.Add(AuditControl)
End Sub
On the control that's being loaded i've exposed the item i want to change as a property
Public Property resultType() As String
Get
Return m_resultType
End Get
Set(ByVal value As String)
m_resultType = value
End Set
End Property
Basically all it is doing is setting a parameter for my table adaptor
Public Sub Load_Data()
dtblog = New dsDECorp.ClientInfoDataTable
dtblog = tablog.GetAudits(m_resultType)
For Each rClient As dsDECorp.ClientInfoRow In dtblog
CID = rClient.ClientID
ClientName = rClient.CompanyName
Next
dtblog.Dispose()
End Sub
How do I pass the parameter through the property from the first control to the second when it loads?
Thanks
Tom
I'm a C# guy so forgive me if I make any syntax errors but the following should work for you:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim AuditControl As Control = LoadControl("~/controls/auditcompanies.ascx")
Dim AuditControlType As Type = AuditControl.GetType()
Dim AuditField As FieldInfo = AuditControlType.GetField("resultType")
AuditField.SetValue(AuditControlType, "Your Value")
phCompanies.Controls.Add(AuditControl)
End Sub
I'm trying to allow users to update their details after logging in on an asp site using vb. Textboxes are populated with user details using session variables in the form_load. The textboxes should be editable but for some reason are not registering the changes when the submit button is clicked.
There is a similar question with the same issue Database not updating after UPDATE SQL statement in ASP.net that was never answered.
Please can someone advise
Thanks in advance
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Txt_Fname.Text = Session("First_Name")
Txt_LName.Text = Session("Last_Name")
Txt_ContactNumber.Text = Session("Cell_Number")
Txt_Email.Text = Session("Email_Address")
End Sub
Protected Sub Cmd_Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Cmd_Submit.Click
Command.Connection = Connection
Command.CommandText = "UPDATE dbo.User_Account Set First_Name = #First_Name, Last_Name = #Last_Name, Cell_Number = #Cell_Number, Email_Address = #Email_Address where Overall_ID = #Overall_ID"
Command.Parameters.AddWithValue("#First_Name", Txt_Fname.Text)
Command.Parameters.AddWithValue("#Last_Name", Txt_LName.Text)
Command.Parameters.AddWithValue("#Cell_Number", Txt_ContactNumber.Text)
Command.Parameters.AddWithValue("#Email_Address", Txt_Email.Text)
Command.Parameters.AddWithValue("#Overall_ID", Session("ID"))
Connection.Open()
Command.ExecuteNonQuery()
Connection.Close()
Response.Redirect("MyAccount.aspx")
End Sub
Add if not page.ispostback before your code in page_load.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Not Page.IsPostBack) then
Txt_Fname.Text = Session("First_Name")
Txt_LName.Text = Session("Last_Name")
Txt_ContactNumber.Text = Session("Cell_Number")
Txt_Email.Text = Session("Email_Address")
End If
End Sub
Do I have to instantiate description every time for different method? Or should I use static? Here's how I'm doing this now: What is the best way of handling this kind of situations. it seems that I repeat this line:Dim description As BLLDescription = New BLLDescription() without any good reasn.
Protected Sub Button8_Click(sender As Object, e As System.EventArgs) Handles Button8.Click
Dim description As BLLDescription = New BLLDescription()
List<String> = description.GetDescriptionWithoutNotes()
.....
End Sub
Protected Sub Button9_Click(sender As Object, e As System.EventArgs) Handles Button9.Click
Dim description As BLLDescription = New BLLDescription()
List<String> = description.GetDescriptionWithNotes()
.....
End Sub
Protected Sub Button10_Click(sender As Object, e As System.EventArgs) Handles Button10.Click
Dim description As BLLDescription = New BLLDescription()
List<String> = description.GetAllDescriptions()
.....
End Sub
IF you define BLLDescription as a static class, you can call the GetAllDescriptions() method without having to instantiate:
Protected Sub Button8_Click(sender As Object, e As System.EventArgs) Handles Button8.Click
List<String> = BLLDescription.GetDescriptionWithoutNotes()
.....
End Sub
Protected Sub Button9_Click(sender As Object, e As System.EventArgs) Handles Button9.Click
List<String> = BLLDescription.GetDescriptionWithNotes()
.....
End Sub
Protected Sub Button10_Click(sender As Object, e As System.EventArgs) Handles Button10.Click
List<String> = BLLDescription.GetAllDescriptions()
.....
End Sub
It depends on what the instance of BLLDescription does and how it gets the data.
If it is accessing the same data again and again, you can declare it as static. If it gets same data per request, then have it as a property at the class level.