Archive for the Category » SubSonic «

Tuesday, May 05th, 2009 | Author: admin
DataTable dt = new DataTable();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindRepeater();
                RepeaterMenu.DataSource = dt;
                RepeaterMenu.DataBind();
            }
        }

        public DataTable BindRepeater()
        {
            dt = new Select()
                    .From<CmsMenu>()
                    .Where(CmsMenu.PublishedColumn)
                    .IsEqualTo(true)
                    .And(CmsMenu.FooterMenuColumn)
                    .IsEqualTo(true)
                    .OrderAsc("sortOrder")
                    .ExecuteDataSet().Tables[0];

            return dt;
        }

Category: ASP.NET, C#, SubSonic  | Leave a Comment
Monday, March 09th, 2009 | Author: admin

Sort and page the results

public SortDirection SortDir
    {
        get
        {
            if (ViewState["sortDirection"] == null)
            {
                ViewState["sortDirection"] = SortDirection.Ascending;
            } return (SortDirection)ViewState["sortDirection"];
        }
        set
        {
            ViewState["sortDirection"] = value;
        }
    }

    DataSet ds = new DataSet();
    DataView dv = new DataView();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGrid();
            GridView1.DataSource = dv;
            GridView1.DataBind();
        }
    }

    private DataView BindGrid()
    {
        ds = new Query(AnthemWeb.DAL.Item.Schema).ExecuteDataSet();

        if (ViewState["sortExpr"] != null)
        {
            dv = new DataView(ds.Tables[0]);
            dv.Sort = (string)ViewState["sortExpr"];
        }
        else
        {
            dv = ds.Tables[0].DefaultView;
        }

        return dv;
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource = BindGrid();
        GridView1.DataBind();
    }

    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        string stExp = e.SortExpression;
        string stDir = string.Empty;
        if (SortDir == SortDirection.Ascending)
        {
            SortDir = SortDirection.Descending;
            stDir = "DESC";
        }
        else
        {
            SortDir = SortDirection.Ascending;
            stDir = "ASC";
        }

        ViewState["sortExpr"] = e.SortExpression + " " + stDir;
        GridView1.DataSource = BindGrid();
        GridView1.DataBind();
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int selectedRowIndex;
        selectedRowIndex = GridView1.SelectedIndex;
        GridViewRow row = GridView1.Rows[selectedRowIndex];
        string ID = row.Cells[0].Text;

        Response.Redirect("customer-details.aspx?ID=" + ID, false);
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindGrid();
    }

Category: ASP.NET, C#, SubSonic  | Leave a Comment
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  | Leave a Comment