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

public partial class InserindoRegistros : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        using (NorthwindDataContext db = new NorthwindDataContext())
        {
            Category cat = new Category()
            {
                CategoryName = "Computadores",
                Description = "Categoria destinada ao cadastro de notebooks e PCs"
            };

            db.Categories.InsertOnSubmit(cat);

            try
            {
                db.SubmitChanges();
                Preencher();
            }
            catch (Exception)
            {
                //Mensagem de erro aqui;
            }
        }
    }

    void Preencher()
    {
        using (NorthwindDataContext db = new NorthwindDataContext())
        {
            var categoria = from c in db.Categories
                            select c;

            GridView1.DataSource = categoria;
            GridView1.DataBind();
        }
    }
}