Friday, March 06th, 2009 | Author: admin

Started this week to use Subsonic to generate my DAL. I got this handy reference from their forum for doing the INSERTS etc…

  private void BindNames()
    {               
        AddBook.DLL.AddressBookCollection list = new AddBook.DLL.AddressBookCollection().OrderByAsc("Name").Load();
        this.ddNames.DataSource = list;
        this.ddNames.DataTextField = "Name";
        this.ddNames.DataValueField = "UserID";
        this.ddNames.DataBind();
    }
    protected void btnSelect_Click(object sender, EventArgs e)
    {
        AddBook.DLL.AddressBook ab = new AddBook.DLL.AddressBook(ddNames.SelectedValue);
        this.tbName.Text = ab.Name;
        this.tbSurname.Text = ab.Surname;
        this.tbAddress.Text = ab.Address;
        this.tbHomePhone.Text = ab.HomePhone;
        this.tbMobilePhone.Text = ab.MobilePhone;      
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        AddBook.DLL.AddressBook ab = new AddBook.DLL.AddressBook(ddNames.SelectedValue);
        AddBook.DLL.AddressBook.Delete(ab.UserID);
        BindNames();       
    }
   

protected void btnUpdate_Click(object sender, EventArgs e)
    {
        AddBook.DLL.AddressBook ab = new AddBook.DLL.AddressBook(ddNames.SelectedValue);
        ab.Name = tbName.Text;
        ab.Surname = tbSurname.Text;
        ab.Address = tbAddress.Text;
        ab.HomePhone = tbHomePhone.Text;
        ab.MobilePhone = tbMobilePhone.Text;
        ab.Save();
        BindNames();
    }

    protected void btnInsert_Click(object sender, EventArgs e)
    {
        AddBook.DLL.AddressBook ab = new AddBook.DLL.AddressBook();
        ab.Name = tbName.Text;
        ab.Surname = tbSurname.Text;
        ab.Address = tbAddress.Text;
        ab.HomePhone = tbHomePhone.Text;
        ab.MobilePhone = tbMobilePhone.Text;
        ab.Save();
        BindNames();
    }

Category: ASP.NET, C#, SubSonic
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply