开发者

What's the easiest approach to showing a table of countries in an ASP.Net application?

开发者 https://www.devze.com 2023-01-13 17:10 出处:网络
Here is my method that returns an IQueryable of Countries: using System; using System.Collections.Generic;

Here is my method that returns an IQueryable of Countries:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace InternationalShipments.Repository
{
    public class CountryRepository
    {
        ShipmentsEntities db = new ShipmentsEntities();

        public IQueryable<Country> FindAll()
        {
            return db.Countries;
        }

        public Country Get(int id)
        {
            return db.Countries.FirstOrDefault(x => x.ID == id);
        }

        public void Add(Country country)
        {
            db.Countries.AddObject(country);
        }

        public void Delete(Country country)
        {
            db.Countries.DeleteObject(country);
        }

     开发者_如何学C   public void Save()
        {
            db.SaveChanges();
        }
    }
}

My intent is to show a form that lets you create new countries and on the same page, continue to display all countries in the DB. So if a user adds a new country, it should display in the table above.

Any guidance?


The easiest way would be to use a Repeater. Using that you can easily bind your data to the control and create an HTML template for the output. If you want something with a little more power, you can try the DataGrid or Gridview


I think a Gridview using a Linq to SQL or SQL Datasource would fit the bill. I recall that the gridview can be customized to include an "add record" feature as well as the ability to edit returned records.

0

精彩评论

暂无评论...
验证码 换一张
取 消