Click here to Skip to main content
14,921,612 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: I can´t get any output from XML and Binary. Pin
Marc Hede8-Dec-19 7:17
MemberMarc Hede8-Dec-19 7:17 
GeneralRe: I can´t get any output from XML and Binary. Pin
Richard MacCutchan8-Dec-19 21:51
mveRichard MacCutchan8-Dec-19 21:51 
QuestionExample Needed Pin
Mycroft Holmes30-Nov-19 12:02
professionalMycroft Holmes30-Nov-19 12:02 
QuestionRe: Example Needed Pin
Maciej Los3-Dec-19 1:53
mveMaciej Los3-Dec-19 1:53 
QuestionProblem with Using Directive Pin
Dawud Ahmad29-Nov-19 17:00
MemberDawud Ahmad29-Nov-19 17:00 
AnswerRe: Problem with Using Directive Pin
phil.o29-Nov-19 22:19
mvephil.o29-Nov-19 22:19 
SuggestionRe: Problem with Using Directive Pin
Richard Deeming3-Dec-19 0:47
mveRichard Deeming3-Dec-19 0:47 
QuestionShould I begin with razor pages or mvc? Pin
Dawud Ahmad29-Nov-19 6:29
MemberDawud Ahmad29-Nov-19 6:29 
AnswerRe: Should I begin with razor pages or mvc? Pin
Richard MacCutchan29-Nov-19 7:27
mveRichard MacCutchan29-Nov-19 7:27 
AnswerRe: Should I begin with razor pages or mvc? Pin
Richard Deeming29-Nov-19 8:01
mveRichard Deeming29-Nov-19 8:01 
QuestionNewbie here. Why is my array list not working? Pin
Marc Hede28-Nov-19 0:31
MemberMarc Hede28-Nov-19 0:31 
I am very new to ASP.net and C#, so I am trying my best, but there are stille many things that confuse me, especially because when I am looking at various examples online they give me different answers to the same solution, which just makes it even more confusing.
I made a person class, with two subclasses (driver and admin), but I can not get the ArrayList to show up when I run my Index file. I only get a parse error.

What do I need to change to make this work?

My person class
public class Person
 {
 public Person(string firstName, string lastName, int age, string email)
 {
 FirstName = firstName;
 LastName = lastName;
 Age = age;
 Email = email;
 }
 public string FirstName { get; set; }
 public string LastName { get; set; }
 public int Age { get; set; }
 public string Email { get; }
 public virtual bool ChangeEmail(string email)
 {
 Email = email;
 return true;
 }
 public override string ToString()
 {
 return $"Name: {FirstName} {LastName}, Age: {Age}, E-mail: {Email}";
 }
 }


My subclasses
public class Driver : Person
 {
 private string v1;
 private string v2;
 private string v3;
 private string v4;
 private string v5;
 public Driver(string firstName, string lastName, int age, string email, int
licenceNumber)
 : base(firstName, lastName, age, email)
 {
 LicenceNumber = licenceNumber;
 }
 public Driver(string v1, string v2, string v3, string v4, string v5)
 {
 this.v1 = v1;
 this.v2 = v2;
 this.v3 = v3;
 this.v4 = v4;
 this.v5 = v5;
 }
 public int LicenceNumber { get; set; }
 public override string ToString()
 {
 return $"Role: Traindriver, LicenceNumber: {LicenceNumber}, " + base.ToString();
 }
 }
 public class Admin : Person
 {
 public Admin(string firstName, string lastName, int age, string email)
 : base(firstName, lastName, age, email)
 {
 }
 public override bool ChangeEmail(string email)
 {
 if (!email.EndsWith("@pig.dk", StringComparison.InvariantCultureIgnoreCase))
 return false;
 return base.ChangeEmail(email);
 }
 public override string ToString()
 {
 return $"Role: Admin, " + base.ToString();
 }
 }
}


My ArrayList
namespace Pig
{
 public partial class Index : System.Web.UI.Page
 {
 public object ListBoxResults { get; private set; }
 public object DriverListBox { get; private set; }
 protected void Page_Load(object sender, EventArgs e)
 {
 Driver d1 = new Driver("Hans", "Christensen", 32, "hans@pig.dk", 123456);
 Driver d2 = new Driver("Peter", "Jensen", 40, "peter@mail.dk", 123456);
 Admin a1 = new Admin("Lene", "Maarud", 55, "lene@pig.dk");
 ArrayList person = new ArrayList();
 ListBoxResults.Items.Add(d1.ToString());
 ListBoxResults.Items.Add(d2.ToString());
 ListBoxResults.Items.Add(a1.ToString());
 }
 }
}


My Index file
<pre><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs"
Inherits="ThePig.index" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <title></title>
</head>
<body>
 <form id="form1" runat="server">
 <div>
 <asp:ListBox ID="ListBoxResults" runat="server" Height="800px"
Width="600px"></asp:ListBox>
 </div>
 </form>
</body>
</html>

AnswerRe: Newbie here. Why is my array list not working? Pin
phil.o28-Nov-19 0:41
mvephil.o28-Nov-19 0:41 
AnswerRe: Newbie here. Why is my array list not working? Pin
Richard Deeming28-Nov-19 1:24
mveRichard Deeming28-Nov-19 1:24 
GeneralRe: Newbie here. Why is my array list not working? Pin
Marc Hede28-Nov-19 6:14
MemberMarc Hede28-Nov-19 6:14 
GeneralRe: Newbie here. Why is my array list not working? Pin
Richard Deeming28-Nov-19 6:39
mveRichard Deeming28-Nov-19 6:39 
GeneralRe: Newbie here. Why is my array list not working? Pin
Marc Hede28-Nov-19 9:09
MemberMarc Hede28-Nov-19 9:09 
GeneralRe: Newbie here. Why is my array list not working? Pin
Richard Deeming29-Nov-19 0:34
mveRichard Deeming29-Nov-19 0:34 
GeneralRe: Newbie here. Why is my array list not working? Pin
Marc Hede29-Nov-19 3:00
MemberMarc Hede29-Nov-19 3:00 
QuestionDuring redirection localhost is not attached and page failed to load Pin
Member 1115418827-Nov-19 23:59
MemberMember 1115418827-Nov-19 23:59 
AnswerRe: During redirection localhost is not attached and page failed to load Pin
Richard Deeming28-Nov-19 1:18
mveRichard Deeming28-Nov-19 1:18 
QuestionASP.net In Visual Studio 2019 Pin
Ebrahimaw20-Nov-19 13:09
MemberEbrahimaw20-Nov-19 13:09 
AnswerRe: ASP.net In Visual Studio 2019 Pin
Eddy Vluggen20-Nov-19 14:03
professionalEddy Vluggen20-Nov-19 14:03 
QuestionSQL Parameter Collection - Not able to assign to SQLCommand Pin
Member 1115418819-Nov-19 6:11
MemberMember 1115418819-Nov-19 6:11 
AnswerRe: SQL Parameter Collection - Not able to assign to SQLCommand Pin
Richard MacCutchan19-Nov-19 6:19
mveRichard MacCutchan19-Nov-19 6:19 
General[Solved] Re: SQL Parameter Collection - Not able to assign to SQLCommand Pin
Member 1115418819-Nov-19 19:10
MemberMember 1115418819-Nov-19 19:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.