Archive for the ‘ASP.NET’ Category

PotgreSQL OLEDB provider for ASP.NET

December 13th, 2007 by Denis Golovtsov

I read the information on the official PostgreSQL site that the first commercial OLEDB provider for PotgreSQL is available now. I estimate this news as very good.

I have been working with PostgreSQL very closely for one year and I found that this server is very powerful and as now .NET framework will have OLEDB provider for a supporting of that, it can be a good alternative of the MS SQL and Oracle servers, licenses of which cost much money.

I have downloaded th trial version of it from the author’s site and have checked how it works. Of course trial version has serious limitation here:

TRIAL VERSION

The trial version has the following limitations:

- SELECT statements return up to 100 rows.
- DB conversion in DTS/SSIS Wizard handles only first 100 rows in every table.

Also I proud that the its developer is Russian programmer, who works and lives in USA now. Thank him very much for his good job. And if I will have .NET project where by some reasons will choose PostgreSQL server I obviously can play with its not trial version also, which doubtless will be interesting.

How add sort direction icons next to the header text in DataGrid (ASP.NET 1.1)

October 11th, 2007 by Denis Golovtsov

This question belongs to FAQ for a long time, but for me as newest in ASP.NET it was not obviously.
So I’d like to present the solution which is mine transformation from ASP.NET 2.0 to ASP.NET 1.1 of found in the Internet.
Original solution can be found there.

public class MyPage: System.Web.UI.Page
{

        protected DataGrid myDataGrid;

        private void Page_Load(object sender, System.EventArgs e)
        {
                if (!Page.IsPostBack)
                {
                        DataBinder();
                }
        }

        // method bind source data to DataGrid control
        private void DataBinder()
        {                     
                DataView objDataView = new DataView(/* …get DateTable object here … */);
                objDataView.Sort = SortExpression;
                myDataGrid.DataSource = objDataView;
                myDataGrid.DataBind();
        }

        // property stores latest sort direction of DataGrid between states
        public string SortDirection
        {
                get
                {
                        return Session[“myDataGridSortDirection”] == null
                                ? “ASC”
                                : Session[“myDataGridSortDirection”].ToString();
                }
                set
                {
                        Session[“myDataGridSortDirection”] = value;
                }
        }

        // property stores latest sort experession of DateGrid between states
        public string SortExpression
        {
                get
                {
                        return Session[“myDataGridSortExpression”] == null
                                ? “ID”
                                : Session[“myDataGridSortExpression”].ToString();
                }
                set
                {
                        Session[“myDataGridSortExpression”] = value;
                }
        }

        // binding event handlers
        private void InitializeComponent()
        {
                this.myDataGrid.ItemCreated
                        += new DataGridItemEventHandler(this.myDataGrid_ItemCreated);
                this.myDataGrid.SortCommand += new DataGridSortCommandEventHandler(this.myDataGrid_SortCommand);
                this.Load += new System.EventHandler(this.Page_Load);

        }

        // below handler is invoked for render every output item of DataGrid
        // this is place and moment when we will add icon image which will show current sort direction
        private void myDataGrid_ItemCreated(object sender, DataGridItemEventArgs e)
        {
                if (e.Item.ItemType != ListItemType.Header) return;
                if (!e.Item.HasControls()) return;

                foreach (Control control in e.Item.Controls)
                {
                        if (!control.HasControls()) continue;
                        LinkButton button = (LinkButton)control.Controls[0];

                        if (button != null && SortExpression.IndexOf(button.CommandArgument) != -1)
                        {
                                HtmlImage image = new HtmlImage();
                                image.Src = “images/sort_”
                                        + ( SortExpression.IndexOf(“ASC”) != -1
                                                ? “asc”
                                                : “desc” )
                                        + “.gif”;
                                control.Controls.Add(image);
                                break;
                        }
                }
        }

        // sort event handler
        private void myDataGrid_SortCommand(object source, DataGridSortCommandEventArgs e)
        {
                SortExpression = e.SortExpression.ToString() + ” “ + SortDirection;
                SortDirection = SortDirection == “ASC” ? “DESC” : “ASC”;
                DataBinder();
        }

}

Comment about SortDirection and SortExpression properties:
I prefer use Session object here, because it gives possibility to restore value, when user left section and then goes back, instead of ViewState, which usually is used for this in almost of solution which I saw in the Internet.