Keep up blogging

By Mohammad Mahdi Ramezanpour at November 30, 2008 20:34
Filed Under: Website

It’s about 3-4 months I didn’t blog so much. It was because of some deterrent elements such as my grandmother, work pressures and more.

Fortunately, those stuffs finished probably and from now on, I’ll try to keep blogging up again.

Lots of bugs fixed on SQL Server 2008

By Mohammad Mahdi Ramezanpour at November 25, 2008 19:40
Filed Under: SQL Server

After SQL Server 2008 RTM released, most of database developers started working with it because of its outstanding features. But unfortunately it had lots of bugs.

Recently, Microsoft released Cumulative update package 1 for SQL Server 2008 that contains a lot of HotFixes for Microsoft SQL Server 2008 RTM and it’s available for download.

As Microsoft said, these hotfixes applies to:

  • Microsoft SQL Server 2008 Analysis Services
  • Microsoft SQL Server 2008 Developer
  • Microsoft SQL Server 2008 Enterprise
  • Microsoft SQL Server 2008 Express
  • Microsoft SQL Server 2008 Express with Advanced Services
  • Microsoft SQL Server 2008 Reporting Services
  • Microsoft SQL Server 2008 Standard
  • Microsoft SQL Server 2008 Standard Edition for Small Business
  • Microsoft SQL Server 2008 Web
  • Microsoft SQL Server 2008 Workgroup

For more details, you can checkout Cumulative update package 1 for SQL Server 2008

Visual Basic 2010 new features

By Mohammad Mahdi Ramezanpour at November 19, 2008 21:39
Filed Under: .NET General, LINQ, XML

Channel 9 Logo - Photo taken from: http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.pngWorking with new technology is always interesting. Since Visual Studio 2010 and .NET Framework 4 have been announced, most of developers who are developing with Visual Basic start searching about Visual Basic 10 new features.

About a month ago, Lucian Wischik and Lisa Feigenbaum described about new features in Visual Basic 2010. The show is available for download at MSDN Channel 9 website.

You can check it out by click here.

This is my recommendation: View it!

How to implement SQL LIKE keyword in LINQ to SQL

By Mohammad Mahdi Ramezanpour at November 17, 2008 18:27
Filed Under: .NET General, LINQ, SQL Server

It’s about a year that .NET framework 3.5 has been released. Most of companies are still using SqlConnection, SqlCommand, SqlDataAdaptor, etc. in order to manager their data connections. About 5 month ago I started posting articles about LINQ to SQL and ways you can use in order to use LINQ as a very powerful data source.

In this post I’m going to show how you can implement SQL “LIKE” keyword in LINQ to SQL.

As you may know, SQL Server has 3 kind of LIKE keywords (%LIKE, %LIKE% and LIKE%). For each of these types, you have to use of specific LINQ to SQL:

LIKE%:

LIKE% selects all rows that start with an expression, for example:

SELECT Title, LoginID FROM HumanResources.Employee 
WHERE Title LIKE N'Acc%'

Here is the return value:

SQL result after using LIKE keyword

In order to implement such a thing in LINQ to SQL you have to use the StartsWith() method like following:

private void ImplementStartsWith()
        {
            AWDataContext db = new AWDataContext();
            var i = from item in db.Employees
                    where item.Title.StartsWith("Acc")
                    select new {Title = item.Title, UserName = item.LoginID };
            dataGridView1.DataSource = i;
        }

%LIKE:

%LIKE selects all rows that end with an expression. For example, I want to have all managers so I select titles that end with “Manager”. EndsWith() method will help you out for this:

private void ImplementEndsWith()
        {
            AWDataContext db = new AWDataContext();
            var i = from item in db.Employees
                    where item.Title.EndsWith("Manager")
                    select new { Title = item.Title, UserName = item.LoginID };
            dataGridView1.DataSource = i;
        }

%LIKE%:

This like is the most useful like type that is using for searches. If you want to have all rows that contain an expression, you must use Contains() method:

private void ImplementContains()
{
        AWDataContext db = new AWDataContext();
        var i = from item in db.Employees
                where item.Title.EndsWith("Specialist")
                select new { Title = item.Title, UserName = item.LoginID };
        dataGridView1.DataSource = i;
}

How to create a tab control using ASP.NET and JavaScript

By Mohammad Mahdi Ramezanpour at November 16, 2008 19:54
Filed Under: .NET General, ASP.NET, Web design, JavaScript

It may happen to any ASP.NET Developer that the customers want to have a Tab Control in their websites. There are many ASP.NET components such as Telerik RAD Controls, ComponentArt, DevExpress, etc. which can help you out in this but sometimes they are expensive for your project capacity.

In this post, I’m going to show you how you can create a very simple Tab Control using ASP.NET and JavaScript.

You can do lots of thing in order to create a Tab Control but what I’m going to do is to create a class that is inherited from System.Web.UI.WebControl:

    public class TabControl : System.Web.UI.WebControls.WebControl
    {
    }

You can make your Tab Control flexible by adding some properties to it. For example, enable your developers to set CssClass to a TabItem:

 

private string _MainCssClass;
private string _ItemCssClass;
private string _InActiveCssClass;
private string _ActiveCssClass; 
private Unit _ItemWidth = 70;
private HorizontalAlign _HorizontalAlign = HorizontalAlign.NotSet;
private string _LinkCssClass;

They’re OK; but the interesting part is to use of a string array in order to store TabItem names:

private string[] _TabNames = { "Item1", "Item2" };

This is also a property, so developers can add their own items. Another important property is a list of Panels of those TabItems. Actually, Panels are the content of each TabName:

private List<Panel> _Panels = new List<Panel>();

In the field above, developers can add their specified panels for each TabItem. The most important method in creating custom web controls is the Render() method which enable you to design your control using HTML tags. Here is my Render() method:

 

protected override void Render(System.Web.UI.HtmlTextWriter w)
{
    if (_Panels.Count == 0 || _Panels == null)
        throw new NullReferenceException("Please specify at least one panel.");
 
    w.WriteLine("<!-- Developed by Mohammad Mahdi Ramezanpour. © 2008 Marlik. -->");
    w.WriteLine(String.Format(@"<table cellpadding=""0"" cellspacing=""0""
    class=""{0}""><tr id=""MarlikTabControl"">", _MainCssClass));
    foreach (Panel p in this.Panels)
    {
        cols.Add("Tab_" + _itemIndex);
        w.WriteLine(String.Format(@"<td onmouseover=""javascript:this.style.cursor='hand';""
        class=""{0} {3}"" align=""{5}"" id=""Tab_{4}"" 
        onclick=""ShowTabContent('{1}', 'Tab_{4}');"" width=""{2}"">",
         _ItemCssClass, p.ClientID, this._ItemWidth, this._InActiveCssClass, 
         this._itemIndex, this._HorizontalAlign.ToString()));
        w.WriteLine(String.Format(@"<a class=""{1} {2}"">{0}</a>",
        _TabNames[_itemIndex], _LinkCssClass,  _ItemCssClass));
        _itemIndex++;
        w.WriteEndTag("td");
    }
    w.Write("</tr></table>");
    w.WriteLine(JavaFunctions().ToString());
    base.Render(w);
}

How it works?

In the first I checked for available panels and if there was no panels so an exception will be throwing using NullReferenceException.

As you know, there is a writer parameter as System.Web.UI.HtmlTextWriter in Render() method that enable you to generate HTML codes in your web component. You have to use that if you want to use HTML or any client-side code in your web control. Add I did above is to create a HTML <table></table> tag but rows and columns will be generating dynamically using HtmlTextWriter.

You can download the full code here: TabControl

Currently Reading

Quote of the day

Send Persian SMS