Place a GridView in the Center of a DIV

To place a GridView in the center of a div one thing that we do is to use the property text-align:center. However as per the current css, it won’t work. What we need to do is to use the code margin-left: auto; margin-right: auto;. Either put that in the css Class of the GridView or you can directly put it inside the Grid like the following

<asp:GridView ID="grdExamSchedules" runat="server" ForeColor="#333333" 
              style="margin-left:auto; margin-right:auto" >

Thanks …


Sort the BlogEngine Page-List Widget [2.8]





This one is for the sorting of Pages in the BlogEngine 2.8 Page-List widget. By default, the sorting of the pages in the list was in the alphabetic order. However, I wanted to sort the page list in custom way. Unfortunately, there is no control/option for sorting the page-list widget.


To sort the page list in custom order you’ll have to write a bit of code.

Open App_Code/Controls/PageList.cs file.
Look for the BindPages() method in it.
Replace the existing code with the following:-

List<BlogEngine.Core.Page> pagesList = new List<BlogEngine.Core.Page>();
var varPagesList = BlogEngine.Core.Page.Pages.OrderBy(p => p.DateCreated);
pagesList = varPagesList.ToList<BlogEngine.Core.Page>();

var ul = new HtmlGenericControl("ul") { ID = "pagelist" };
ul.Attributes.Add("class", "pagelist");

foreach (var page in pagesList.Where(page => page.ShowInList && page.IsVisibleToPublic))
	var li = new HtmlGenericControl("li");
	var href = page.RelativeLink;
	if (BlogSettings.Instance.RemoveExtensionsFromUrls && !string.IsNullOrEmpty(BlogConfig.FileExtension))
	  href = href.Replace(BlogConfig.FileExtension, "");

	var anc = new HtmlAnchor { HRef = href, InnerHtml = page.Title, Title = page.Description };


return ul;

Now the Page inside that widget will be listed according to their created date field. We can easily modify this field to put a page at the top or at the bottom of the list. To do that, you have to open  App_Data/pages xml-files . These xml files are the description of your pages in the blog. If you open it you will get the created date property there which you can easily modify. A snapshot of one of my page is give below for better understanding.

Thanks …

Sort Asp.Net GridView Column

Well, it’s a very simple feature, still if you forget it, it may cause you unnecessary trouble. So here’s the code for it.

Here, I will create a custom property of type SortDirection.
Now on GridView’s Sorting event, I will check the ViewState – sortDirection value and accordingly I will sort the given Column.

DataTable dt = ((DataSet)ViewState[“ClientDetails”]).Tables[0];
DataView dView = new DataView(dt);

if (GridViewSortDirection == SortDirection.Ascending)
	GridViewSortDirection = SortDirection.Descending;
	dView.Sort = e.SortExpression + ” DESC”;
	GridViewSortDirection = SortDirection.Ascending;
	dView.Sort = e.SortExpression + ” ASC”;
grdView1.DataSource = dView;

And we also need to declare the property GridViewSortDirection of type SortDirection. which will declare the ViewState – sortDirection as Ascending for the page if its value is found to be null.

public SortDirection GridViewSortDirection
		if (ViewState[“sortDirection”] == null)
		ViewState[“sortDirection”] = SortDirection.Ascending;
		return (SortDirection)ViewState[“sortDirection”];
		ViewState[“sortDirection”] = value;

That’s it!!!