ASP.NET – How to work with GridView

Today we are going to see how to work with Grid View Control.

Here is an example how are we going to get a repeater after we finished coding.

Here I am using AdventureWorks in SQL SERVER which can be downloaded from codeplex.

The table I am using is DimCustomer and fields are :






Step 1 :  Add the control in the <body> tag in page in .aspx side let it be grdView.aspx

<form id="frmExmGrdView" runat="server">
    <asp:GridView ID="grd" runat="server" CssClass="gdview" HeaderStyle-CssClass="hd" AutoGenerateColumns="false" BorderStyle="None">
    <asp:BoundField DataField="FirstName" HeaderText="Login" ItemStyle-Width="40" ItemStyle-HorizontalAlign="Left" ></asp:BoundField>
    <asp:BoundField DataField="MiddleName" HeaderText="Initial" ItemStyle-Width="20" ItemStyle-HorizontalAlign="Left" ></asp:BoundField>
    <asp:BoundField DataField="LastName" HeaderText="Name" ItemStyle-Width="60" ItemStyle-HorizontalAlign="Left" ></asp:BoundField>
    <asp:BoundField DataField="BirthDate" HeaderText="DateAdded" ItemStyle-Width="40" ItemStyle-HorizontalAlign="Left" HtmlEncode="false" DataFormatString={0:d}></asp:BoundField>

NOTE: Dont forget to make the form tag as runat = “server “

otherwise an error will occur because you are trying to insert the data from .cs

side but u can only access it when u make runat = “server “

STEP 2:  Now insert the data from the code behind (.cs side) in Page_Load event


protected void Page_Load(object sender, EventArgs e)
        SqlConnection con = new SqlConnection("Server=localhost;UID=sa;PWD=dilip;Database=AdventureWorksDW");
        string sSQL = "Select top 5 * from dbo.DimCustomer";
        SqlCommand cmd = new SqlCommand(sSQL, con);
        SqlDataReader dtrClient = cmd.ExecuteReader();
        grd.DataSource = dtrClient;

The last 2 lines binding the data to the repeater and starting remaining lines is to establish connection to database.

the output will come as shown above .

Reference : Dilip Kumar Jena ( )

DOT NET – Maintaining user information for Security & other requirements

– Create login.aspx in the root directory and design the page according to requirement. Code for this should be written after completing preperation of Entities, DL, BL and others…..

– Goto DB that the project is configured and create tables for storing user information. In general userinformation will have multiple tables, many columns but in our example
we will create users table with username(pk),password,role.

– Add some sample data in the created table and optionally write procedures for accessing the created tables.[In real time highly recommended is access tables with procedures]

– Once db is prepared we have to prepare front-end layers and as usual we will use EDM(O-R) for preparing our objects. prepare edm objects.

– once EDM objects are prepared we have create BL for users where we have to provide all functionality.

– Now we can write code for login button of login page. In this button we have to pass userdetails to bl and on successfull evaluation i.e when it returns true we must create forms identity.

class prjuser
string _uname,_password;



c1 obj=new c1();

class c2 : c1

Reference : Dilip Kumar Jena ( )

DOT NET – What is a cookie

Recently I got a message from one of the reader of my site that what exactly is a cookie. So I decided to wire a post dedicated to it .

  1. A cookie is name=value pair like variable which is stored as a file(persistant cookie) and which travels automatically between every request and response.
  2. Cookies are based on domains(website). As long as user is working with current web site cookie will be available.
  3. Cookies are maintained by browser but not by server which means cookies based websites are dependent on client.
  4. Cookies can be created as
    (i) In-memory cookie
    (ii) Persistant Cookie

An In-memory cookie means as long as user is working with app it will be available – also called as Session Cookie.

Persistant cookie means it will be stored in client physical location and available online as well as offline.

Reference : Dilip Kumar Jena ( )

DOT NET 4.0 – Concerns and criticisms relating to .NET

Here are most known Criticisms

  • Applications running in a managed environment such as the Microsoft framework’s CLR or Java’s JVM tend to require more system resources than similar applications that access machine resources more directly. Some applications, however, have been shown to perform better in .NET than in their native version. This could be due to the runtime optimizations made possible by such an environment, the use of relatively well-performing functions in the .NET framework, just-in-time compilation of managed code, or other aspects of the CLR.


  • As JIT languages can be more easily reverse-engineered than native code to algorithms used by an application there is concern over possible loss of trade secrets and the bypassing of license control mechanisms. Many obfuscation techniques already developed, however, can help to prevent this; indeed Microsoft’s Visual Studio 2005 includes such a tool.


  • In a managed environment such as the Microsoft framework’s CLR or Java’s JVM the regularly occurring garbage collection for reclaiming memory suspends execution of the application for an unpredictable lapse of time (typically no more than a few milliseconds).


  • Since the framework is not pre-installed on older versions of Windows an application that requires it must verify that it is present, and if it is not, guide the user to install it.


  • Newer versions of the framework (3.5 and up) are not pre-installed on any versions of the Windows operating system. Some developers have expressed concerns about the large size (around 54 MB for end-users with .NET 3.0 and 65 MB with .NET 3.5).

Reference : Dilip Kumar Jena ( )


DOT NET 4.0 – Features of DOT NET


Because interaction between new and older applications is commonly required, the .NET Framework provides means to access functionality that is implemented in programs that execute outside the .NET environment. Access to COM components is provided in the System.Runtime.InteropServices and System.EnterpriseServices of the framework.


Common Runtime Engine

Programming languages on the .NET Framework compile into an intermediate language known as the Common Intermediate Language (CIL). In Microsoft’s implementation this intermediate language is not interpreted but rather compiled in a manner known as just-in-time compilation (JIT) into native code.


Language Independence

The .NET Framework introduces a Common Type System, or CTS. The CTS specification defines all possible datatypes and programming constructs supported by the CLR and how they may or may not interact with each other. Because of this feature, the .NET Framework supports the exchange of instances of types between programs written in any of the .NET languages.


Base Class Library

The Base Class Library (BCL), part of the Framework Class Library (FCL), is a library of functionality available to all languages using the .NET Framework. The BCL provides classes which encapsulate a number of common functions.


Simplified Deployment

Installation of computer software must be carefully managed to ensure that it does not interfere with previously installed software, and that it conforms to increasingly stringent security requirements. The .NET framework includes design features and tools that help address these requirements.



The design of the .NET Framework allows it to theoretically be platform agnostic, and thus cross-platform compatible. That is, a program written to use the framework should run without change on any type of system for which the framework is implemented. Microsoft’s commercial implementations of the framework cover Windows. In addition, Microsoft submits the specifications for the Common Language Infrastructure (which includes the core class libraries, Common Type System, and the Common Intermediate Language), the C# language to both ECMA and the ISO, making them available as open standards. This makes it possible for third parties to create compatible implementations of the framework and its languages on other platforms.


Memory management

It is the act of managing computer memory. In its simpler forms, this involves providing ways to allocate portions of memory to programs at their request, and freeing it for reuse when no longer needed.

The management of main memory is critical to the computer system. In this process it uses the Garbage Collection which is the automated allocation, and deallocation of computer memory resources for a program.

This is generally implemented at the programming language level and is in opposition to manual memory management, the explicit allocation and deallocation of computer memory resources.

In computer science, garbage collection (GC) is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory used by objects that will never be accessed or mutated again by the application. Garbage collection was invented by John McCarthy around 1959 to solve the problems of manual memory management.

Reference : Dilip Kumar Jena ( )

Dot Net 4.0 – Windows Communication Foundation (WCF)

Windows Communication Foundation (WCF)

It is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. There are many other such technologies, including the Component Object Model and Distributed Component Object Model, Remote Method Invocation, Microsoft Message Queuing (MSMQ), and WebSphere MQ.

A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application. An endpoint can be a client of a service that requests data from a service endpoint. The messages can be as simple as a single character or word sent as XML, or as complex as a stream of binary data. A few sample scenarios include:

  • A secure service to process business transactions.
  • A service that supplies current data to others, such as a traffic report or other monitoring service.
  • A chat service that allows two people to communicate or exchange data in real time.
  • A dashboard application that polls one or more services for data and presents it in a logical presentation.
  • Exposing a workflow implemented using Windows Workflow Foundation as a WCF service.
  • A Silverlight application to poll a service for the latest data feeds.

While creating such applications was possible prior to the existence of WCF, WCF makes the development of endpoints easier than ever. In summary, WCF is designed to offer a manageable approach to creating Web services and Web service clients.

We develop WCF as contracts, interface, operations, and data contracts. As the developer we are more focused on the business logic services and need not worry about channel stack. WCF is a unified programming API for any kind of services so we create the service and use configuration information to set up the communication mechanism like HTTP/TCP/MSMQ etc

  • ASMX is IIS and HTTP only – WCF gives you HTTP, NetTcp, MSMQ, IPC – you name it

you can write your service once, and expose it on multiple endpoints

  • self-hosting: you can host your WCF service in a console app, a Winforms app, a WPF app, or let it be handled by IIS/WAS
  • a lot more options like reliable sessions, lot more security options
  • you don’t have to deal with as much in WCF as you do in ASMX – you can concentrate on your business problem, and let the config and attributes handle all the stuff you don’t want to deal with.

ASMX is:

  • easy and simple to write and configure
  • only available in IIS
  • only callable from HTTP

WCF can be:

  • hosted in IIS, a Windows Service, a Winforms application, a console app – you have total freedom
  • used with HTTP (REST and SOAP), TCP/IP, MSMQ and many more protocols

1)Web services can only be invoked by HTTP (traditional webservice with .asmx). While WCF Service or a WCF component can be invoked by any protocol (like http, tcp etc.) and any transport type.

2) web services are not flexible. However, WCF Services are flexible. If you make a new version of the service then you need to just expose a new end. Therefore, services are agile and which is a very practical approach looking at the current business trends.

What Does WCF replace


Rather than requiring different technologies for different communication styles, WCF provides a single unified solution.

1) Component Object Model (COM) It is used to enable interprocess communication and dynamic object creation in a large range of programming languages.

2) Distributed Component Object Model (DCOM) communication among software components distributed across networked computers.

3) MSMQ is essentially a messaging protocol that allows applications running on separate servers/processes to communicate in a failsafe manner.

4) WebSphere MQ is the most popular system for messaging across multiple platforms, including Windows, Linux, OS/2, IBM mainframe and midrange, and Unix. WebSphere MQ is often referred to as “MQ” or “MQ Series”.

5) Web Services Enhancements for .NET (WSE) is a product that enables you to build secure Web services quickly and easily.

6) .NET remoting enables you to build widely distributed applications easily, whether application components are all on one computer or spread out across the entire world


WCF is meant for design and deploying distributed applications under SOA (Service Oriented Architecture) implementation.

WCF is designed in accordance with service oriented architecture principles to support distributed computing where services are consumed by consumers. Clients can consume multiple services and services can be consumed by multiple clients. Services are loosely coupled to each other. Services typically have a WSDL interface (Web Services Description Language) that any WCF client can use to consume the service, irrespective of which platform the service is hosted on. WCF implements many advanced Web services (WS) standards such as WS-AddressingWS-Reliable Messaging and WS-Security. With the release of .NET Framework 4.0, WCF also provides RSS Syndication Services.


A WCF client connects to a WCF service via an Endpoint. Each service exposes its contract via one or more endpoints. An endpoint has an address, which is a URL specifying where the endpoint can be accessed, and binding properties that specify how the data will be transferred.

The mnemonic “ABC” can be used to remember address/binding[disambiguation needed]Contract. Binding specifies what communication protocols are used to access the service, whether security mechanisms are to be used, and the like. WCF includes predefined bindings for most common communication protocols such as SOAP over HTTP, SOAP over TCP, and SOAP over Message Queues, etc. Interaction between WCF endpoint and client is done using a SOAP envelope. SOAP envelopes are in simple XML form that makes WCF platform independent.

When a client wants to access the service via an endpoint, it not only needs to know the contract, but it also has to adhere to the binding specified by the endpoint. Thus, both client and server must have compatible endpoints.

With the release of the .NET Framework 3.5 in November 2007, Microsoft released an encoder that added support for the JSON serialization format to WCF.[1] This allows WCF service endpoints to service requests from AJAX-powered Web pages.


The rental car reservation application provides WCF-based services that can be accessed by various clients.

Unification of Microsoft’s Distributed Computing Technologies

Think about the team of developers implementing the rental car reservation application described earlier. In the world before WCF, this team would need to choose the right distributed technology from the multiple choices originally offered by the .NET Framework. Yet given the diverse requirements of this application, no single technology would fit the bill. Instead, the application would probably use several of these older .NET technologies. For example:

1)  ASMX, also called ASP.NET Web Services, would be an option for communicating with the Java EE-based reservation application and with the partner applications across the Internet. Given that Web services are widely supported today, this would likely be the most direct way to achieve cross-vendor interoperability.

2) .NET Remoting is a natural choice for communication with the call center application, since both are built on the .NET Framework. Remoting is designed expressly for .NET-to-.NET communication, so it would offer the best performance for this situation.

3) Enterprise Services might be used by the rental car reservation application for things such as managing object lifetimes and defining distributed transactions. These functions could be useful in communicating with any of the other applications in this scenario, but Enterprise Services supports only a limited set of communication protocols.

4) Web Services Enhancements (WSE) might be used along with ASMX to communicate with the Java EE-based reservation application and with the partner applications. Because it implements more advanced SOAP-based standards, known collectively as the WS-* specifications, WSE can allow better security and more, as long as all applications involved support compatible versions of these specifications.

5) System.Messaging, which provides a programming interface to Microsoft Message Queuing (MSMQ), could be used to communicate with Windows-based partner applications that weren’t always available. The persistent queuing that MSMQ provides is typically the best solution for intermittently connected applications.

6) System.Net might be used to communicate with partner applications or perhaps in other ways. Using this approach, developers can create applications that use the HTTP-based communication style known as Representational State Transfer (REST).

If it were built on an earlier version of the .NET Framework, the rental car reservation application would need to use more than one of these communication technologies, and maybe even all of them, to meet its requirements. Although this is technically possible, the resulting application would be complex to implement and challenging to maintain. A better solution is needed.

WS – Protocol Support

Security, Reliable Messaging, Transactions, Metadata, Messaging, XML.

Where it can be used

business-to-business (B2B)
business-to-consumer (B2C),
Interoperability with other platforms and technologies
messaging for any kind of communication
and for all the kind of services that were earlier developed using ASMX, WSE, Web Services, MSMQ, and distributed stack. It also helps in creating the distributed application in a very easy manner that earlier would have involved the usage of two or more distributed technology. These custom solution were earlier not possible to develop in either web services or .NET Remoting. WCF facilitates in building these custom solutions. WCF provides a Uniform programming model to creating distributed applications and has been designed to support  Service orientation… many more

Performance Characteristics

In most cases these can be used but might change according to the requirement.

Note : This article is written taking reference from msdn and other standard microsoft sites just to give a clear Idea how this technology works i have compiled into one, also my personal views are written this should not be taken for granted.

Reference : Dilip Kumar Jena ( )