studio NETSOULS

Applying Web To Your Business

First off, the code-behind model has changed. In the @Page directive, accessing your code behind is accomplish via the CodeFile attribute instead of the Code behind or Src attribute. Also much of the used to DataGrid properties have changed, as seen below:

.NET 1.1 DataGrid

.NET 2.0 GridView

CurrentPageIndex

PageIndex

OnPageIndexChanged

OnPageIndexChanging

OnSortCommand

OnSorting

DataKeyField

DataKeyNames

SelectedItemStyle

SelectedRowStyle

ItemStyle

RowStyle

TemplateColumn

TemplateField

BoundColumn

BoundField

DataGrid.Items

GridView.Rows

DataGridItem

GridViewRow

DataGridItem (ItemIndex)

GridViewRow (RowIndex).Value

DataGridPageChangedEventArgs

GridViewPageEventArgs

DataGridSortCommandEventArgs

GridViewSortEventArgs

The CurrentPageIndex which gets or sets the index of the currently displayed page is now simply PageIndex. Setting up paging and sorting in the Gridview has changed from the OnPageIndexChanged and OnSortCommand methods to OnPageIndexChanging and OnSorting, respectively. The primary key field for the items displayed in the GridView has also changed from DataKeyField to DataKeyNames property.

Setting up row colors on the grid is no more SelectedItemStyle or ItemStyle but rather SelectedRowStyle and RowStyle. I guess this makes more sense since it is a row, anyway. The TemplateColumn class that displays custom content in a data-bound control is now TemplateField, and its partner the BoundColumn which represents a field that is displayed as text in a data-bound control is now called BoundField.

Next, in our code-behind, .NET 2.0 utilizes a new language feature known as a Partial. A Partial class is just that, a partial, incomplete definition of the class or structure. So all that is included in the partial class in only the code needed, such as event handlers and the like. .NET infers the control instances and it derives the events bound from the .aspx file during compilation. Notice in the code behind I didn’t have to declare the GridView or the OutputMsg controls there, as I did in the DataGrid version, neither did I need to include most of the Imports statements that were there before!

Another change in the framework went to the RegisterClientScriptBlock method, this now obsolete method needs to be ClientScript.RegisterClientScriptBlock (Type type, string key, string script) or in our code ClientScript.RegisterClientScriptBlock (Me.GetType(),”clientScript”, jsScript.ToString()).

As for implementing custom paging, this also has changed its class wording from DataGridPageChangedEventArgs to GridViewPageEventArgs.

In Short the main diffrence betbeen GridView and DataGrid is:
Sorting: In DataGrid code requires to handle the SortCommand event and rebind grid required. In case of GridView no additional code required.
Paging: In DataGrid requires code to handle the PageIndexChanged event and rebind grid required. In case of GridView no additional code required. It also supports customized appearance.
Data binding: Like GridView DataGrid cannot bind with new datasource control in ASP.NET 2.0. Updating data:  DataGrid requires extensive code to update operation on data. GridView  requires little code. Code like exceptions handling for database part.
Events: GridView supports events fired before and after database updates. In DataGrid less events supported as compared to GridView.

  • Currently 4 /5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

I am always searching the internet for the DateTime formats, so i thought i will post it in my blog so that i don’t need to keep googling for it.

Specifier String Result Output
d dd-MM-yyyy 03-01-2009
D dd MMMM yyyy 03 January 2009
f dd MMMM yyyy HH:mm:ss 03 January 2009 17:31:14
g MM/dd/yyyy HH:mm 03-01-2009 17:31:14
m MMMM dd January 03
r ddd, dd MMM yyyy HH':'mm':'ss 'GMT' Sat, 03 Jan 2009 17:31:14 GMT
s yyyy'-'MM'-'dd'T'HH':'mm':'ss 2009-01-03T17:31:14
t HH:mm:ss 17:31:14
u yyyy'-'MM'-'dd HH':'mm':'ss'Z' 2009-01-03 17:31:14Z
U dd MMMM yyyy HH:mm:ss 03 January 2009 12:01:14
y MMMM, yyyy January, 2009
o yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK 2009-01-03T17:31:14.0303453+05:30
DateTime todayDate = DateTime.Now;
string dateToStringInFormat = todayDate.ToString(formatSpecifier, 
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat)
  • Currently 0 /5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

A lot of times in the applications we require to pass comma separated values to the stored procedures, these values are contained in a custom object IList or IList<string> type. 

/// <summary>
/// Converts a list item property name value to comma seperated values
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Items"></param>
/// <param name="PropertyName"></param>
/// <returns></returns>
public static string ConvertTo<T>(IList<T> Items, string PropertyName) 
{
    StringBuilder builder = new StringBuilder();
    Type entityType = typeof(T);
 
    // iterate through the property
    foreach (T Item in Items)
    {
        if (string.IsNullOrEmpty(PropertyName))
            builder.Append(Item.ToString()).Append(",");
        else 
            // get the value of the property name passed
            builder.Append(
                entityType.GetProperty(PropertyName).GetValue(Item, null).ToString()
            ).Append(",");
    }
 
    return builder.ToString().TrimEnd(new char[] { ',' });
}
  • Currently 2 /5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

If you've worked on creating a Data Access Layer you know how frustrating it can be to determine the type of data your DAL will be handling. For that reason, creating a converter that works with generics or vica-versa can be the long term answer.

Alright, so for our applications we have a couple of forms that use the DataGridView control to display tabular data (kinda of a common scenario for many business applications). The data is returned from our services as an IList<T> in which we can just then bind directly to the grid by using the grid's DataSource property.  Pretty easy task...unless when it comes to data manipulations.

So, what we decided to was take the easy way out and that is convert our IList<T> to a DataTable object with the correct schema (for the primitive types) that our contained objects have.  Here's what we came up with:More...

  • Currently 4 /5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

I lot of times in our Business Object Model we use enums, these enum property could be a string, integer or a short value. While retrieving records from the database we need to set the property in the BOM to that of the enum value.

Here is one of those methods that you can never find when you're looking for it

   1: // suppose we have a enum
   2: enum PublishingStatus : short
   3: {
   4:     Draft = 1,
   5:     PendingApproval = 2,
   6:     Active = 3,
   7:     Archived = 4,
   8:     PendingDeletion = 5
   9: }
  10:  
  11: //set a default value
  12: PublishingStatusEnum CurrentPublishingStatus = PublishingStatusEnum.Draft;
  13: if (Enum.IsDefined(typeof(PublishingStatusEnum), Helper.GetShort(Reader["CurrentPublishingStatusId"])))
  14:     CurrentPublishingStatus = (PublishingStatusEnum)Enum.Parse(typeof(PublishingStatusEnum), Reader["CurrentPublishingStatusId"].ToString());
  15:  
  16: // suppose we have a string enum
  17: enum SiteColors
  18: {
  19:     Red,
  20:     Blue,
  21:     Orange
  22: }
  23:  
  24: //set a default value
  25: SiteColors SelectedColor = SiteColors.Red;
  26: if (Enum.IsDefined(typeof(SiteColors), Reader["SiteColor"].ToString()))
  27:     SelectedColor = (SiteColors)Enum.Parse(typeof(SiteColors), Reader["SiteColor"].ToString(),true);
  28: // we passed the last variable as true of ignoreCase
  • Currently 0 /5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

About Us

studio NETSOULS is a complete IT services company, offering strategy, design, development and implementation of the total solution for your web and IT initiatives. The solutions we provide, enables businesses to leverage leading edge technology to gain sustainable competitive advantages in today's marketplace.

We specialize in designing, developing and deploying the next generation of IT solutions including e-business solutions Read more...

Tags

This will be shown to users with no Flash or Javascript.

Contact Us

My status

Quote of the Day

Men are disturbed, not by the things that happen, but by their opinion of the things that happen

- Epictetus

NutritionVista

www.NutritionVista.com

Archives


Advertisements


Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Log in