Click here to Skip to main content
15,908,673 members
Home / Discussions / C#
   

C#

 
GeneralRe: Combobox to filter a datagrid c# Pin
Member 114494475-Jan-16 22:59
Member 114494475-Jan-16 22:59 
GeneralRe: Combobox to filter a datagrid c# Pin
Sascha Lefèvre6-Jan-16 0:26
professionalSascha Lefèvre6-Jan-16 0:26 
QuestionHow to merge same cells value into single cell in C# Pin
Ashfaque Hussain4-Jan-16 2:50
Ashfaque Hussain4-Jan-16 2:50 
SuggestionRe: How to merge same cells value into single cell in C# Pin
Sascha Lefèvre4-Jan-16 3:16
professionalSascha Lefèvre4-Jan-16 3:16 
GeneralRe: How to merge same cells value into single cell in C# Pin
Ashfaque Hussain4-Jan-16 18:51
Ashfaque Hussain4-Jan-16 18:51 
GeneralRe: How to merge same cells value into single cell in C# Pin
Richard Deeming5-Jan-16 2:22
mveRichard Deeming5-Jan-16 2:22 
SuggestionRe: How to merge same cells value into single cell in C# Pin
Richard Deeming4-Jan-16 3:17
mveRichard Deeming4-Jan-16 3:17 
QuestionDisplaying Objects In A List Inside A Foreach Loop Pin
MadDashCoder3-Jan-16 19:22
MadDashCoder3-Jan-16 19:22 
Hi, I have an Employee class with Name, Department, and Salary as properties. All I'm trying to do is add an employee to a list of Employees after typing in all the required info and hitting the Add button on my form.

Then I want to display the employees in the list of Employees using a foreach loop. Below are my code but they're not working and I get no errors.
C#
namespace CSharpListObjects
{
    public partial class Form1: System.Web.UI.Page
    {
        List<Employee> employees = new List<Employee>();

        protected void Page_Load(object sender, EventArgs e)
        {            
        }

        protected void btnShowEmployees_Click(object sender, EventArgs e)
        {
            StringBuilder employeeDetails = new StringBuilder();

            foreach(Employee e in employees)
            {
                employeeDetails.Append("< br/>Name: " + e.Name                
                + " Department: " + e.Department 
                + " Salary: " +  e.Salary + "< br/ >");
            }

            Literal1.Text = employeeDetails.ToString();
        }

       protected void btnAddEmployee_Click(object sender, EventArgs e)
       {

         Employee employee = new Employee();

         employee.Name = txtName.Text;

         employee.Department = txtDepartment.Text;

         employee.Salary = Convert.ToInt32(txtSalary.Text);

         employees.Add(employee);
       }
    }
}

It appears there is nothing in List < Employee > after I added Employee objects. Please help point out where my mistake is if you can spot it, thanks.

modified 4-Jan-16 2:05am.

AnswerRe: Displaying Objects In A List Inside A Foreach Loop Pin
Pete O'Hanlon3-Jan-16 20:02
mvePete O'Hanlon3-Jan-16 20:02 
GeneralRe: Displaying Objects In A List Inside A Foreach Loop Pin
MadDashCoder3-Jan-16 20:19
MadDashCoder3-Jan-16 20:19 
QuestionDynamic Localization for released products Pin
Chandra Mohan BS3-Jan-16 18:28
Chandra Mohan BS3-Jan-16 18:28 
QuestionFingerprint student attendance Pin
Nareen Nair3-Jan-16 4:53
Nareen Nair3-Jan-16 4:53 
SuggestionRe: Fingerprint student attendance Pin
Richard MacCutchan3-Jan-16 5:04
mveRichard MacCutchan3-Jan-16 5:04 
GeneralRe: Fingerprint student attendance Pin
Redgum4-Jan-16 10:17
professionalRedgum4-Jan-16 10:17 
GeneralRe: Fingerprint student attendance Pin
Pete O'Hanlon4-Jan-16 10:41
mvePete O'Hanlon4-Jan-16 10:41 
AnswerRe: Fingerprint student attendance Pin
Richard MacCutchan29-Jan-16 6:35
mveRichard MacCutchan29-Jan-16 6:35 
GeneralRe: Fingerprint student attendance Pin
Nareen Nair29-Jan-16 23:28
Nareen Nair29-Jan-16 23:28 
GeneralRe: Fingerprint student attendance Pin
Richard MacCutchan29-Jan-16 23:54
mveRichard MacCutchan29-Jan-16 23:54 
GeneralRe: Fingerprint student attendance Pin
Nareen Nair31-Jan-16 1:03
Nareen Nair31-Jan-16 1:03 
GeneralRe: Fingerprint student attendance Pin
Richard MacCutchan31-Jan-16 1:56
mveRichard MacCutchan31-Jan-16 1:56 
GeneralRe: Fingerprint student attendance Pin
Nareen Nair31-Jan-16 19:20
Nareen Nair31-Jan-16 19:20 
QuestionHow to reference a deletegate to a static member of each Form Pin
alamdarAfridi1-Jan-16 23:45
alamdarAfridi1-Jan-16 23:45 
AnswerRe: How to reference a deletegate to a static member of each Form Pin
OriginalGriff2-Jan-16 0:41
mveOriginalGriff2-Jan-16 0:41 
AnswerRe: How to reference a deletegate to a static member of each Form Pin
BillWoodruff2-Jan-16 1:10
professionalBillWoodruff2-Jan-16 1:10 
GeneralRe: How to reference a deletegate to a static member of each Form Pin
Pete O'Hanlon5-Jan-16 21:32
mvePete O'Hanlon5-Jan-16 21:32 

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.