Archive for October, 2007

Russia - England 2:1

October 17th, 2007 by Denis Golovtsov

Ole, Ole, Ole - Russia, Go-Go-Go!

We are the Champions!

It was wonderful.

I have fell as we would had won Brazilian in final of World Champions …

It is big gift our players to whole Russian people, thank all of them for this !!!

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.

GolDen blog relive!

October 11th, 2007 by Denis Golovtsov

During 22 September when our administrator start to prepare our servers for a journey to new office, my site hasn’t worked and I haven’t marked it because from local network it still works fine ;) Before one of my colleagues (Alexander Stankevitch it’s you) told me that he cannot access to my site, I didn’t believe him and told that may be he try use not enough good browser for my site ;), but 1 day ago suddenly I understand that problem really takes place, because IP of hosting server was changed and I need update DNS settings for that. So I did update of DNS and site relive again! Thank you Alexander very much!