Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7685125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:10:58+00:00 2026-05-31T19:10:58+00:00

I created a asp.net website. and added a class file to it. i wrote

  • 0

I created a asp.net website. and added a class file to it. i wrote this code in classfile.(person.cs)

public class Person
{
public string name{get; set;}
public int age { get; set; }
public float sal { get; set; }

public Person(string n, int a, float s)
{
    name = n;
    age = a;
    sal = s;
}


public List<Person> getDetails()
{
    Person p1 = new Person("John",21,10000);
    Person p2 = new Person("Smith",22,20000);
    Person p3 = new Person("Cena",23,30000);
    List<Person> li = new List<Person>();
    li.Add(p1);
    li.Add(p2);
    li.Add(p3);
    return li;
}

}

and i want this list to display in my gridview.

so, i have added a default page in website. then what should i write in default.aspx.cs file?so that my list values are shown on gridview?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:10:59+00:00Added an answer on May 31, 2026 at 7:10 pm

    Make the method static:

    public static List<Person> getDetails()
    {
        Person p1 = new Person("John",21,10000);
        Person p2 = new Person("Smith",22,20000);
        Person p3 = new Person("Cena",23,30000);
        List<Person> li = new List<Person>();
        li.Add(p1);
        li.Add(p2);
        li.Add(p3);
        return li;
    }
    

    And use it from default.aspx.cs like this:

        gridView.DataSource = Person.getDetails();
        gridView.DataBind();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a asp.net website and i added tooltip to a button by
I'm trying to run a freshly created ASP.NET Website using C#, however when I
I created a new ASP.NET website using Visual Web Developer 2008 Express edition and
I've created a website with ASP.NET MVC. I have a number of static pages
okay...im really puzzled with this. I want to create a regular asp.net webforms website
I've created a new vs.net project and added all the files from an asp.net
What's the recommended way to deploy a website created with ASP.NET 4.0 and Visual
I have created an asp.net website, with the accompanying app_code folder. In the same
I'm using ASP.NET MVC 3 code-first and I have added validation data annotations to
I'm trying to create two ASP.NET Membership login pages for an ASP.NET website I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.