Displaying data in data grid

The DataGrid control displays the fields of a data source as columns in a table. Each row in the control represents a record in the data source .The control supports selection, editing, deleting, paging, and sorting.

The DataGrid control with strong features is the most complicated control included within the ASP.NET framework. Link the Repeater and DataList controls,it enables to format and display records from a database table. However, it has several advanced features, such as support for sorting through records, which makes it unique.

Records can be displaying in a DataGrid without using templates, a data source can be simply bound to the DtaGrid, and it automatically displaying the records.

Loop Structures

Loops allow you to repeats a segments of code multiple times. C# has three basic types of loops.You choose the types of loop based on the type of task you need to perform. Your choices are as follows:

- You can loop a set of number of times a for loop.
- You can loop through all the times in a collection of data using a foreach loop.
- You can loop while a certain condition holds true, using a while loop.

Conditional Structures

In many ways, conditional logic(deciding which action to take based on user input, external conditions, or other information), is the heart programming. All conditional logic starts with a condition: a simple expression that can be evaluated to true or false. Your code can them make a decision to execute different logic depending on the outcome of the condition. To build a condition, you can use any combination of literal values or variables along with logical operators.

Date Time Object and TimeSpan Types Object

The DateTime and TimeSpan data types also have built-in methods and properties. These class members allow you to perform three useful tasks:

1. Extract a part of a DateTime(for example, just the year) or convert a TimeSpan to a specific representation(Such as the total number of days or total number of minutes).
2. Easily perform date calculations.
3. Determine the current date and time and other information(such as the day of the week or whether the date occurs in a leap year).

Object Based Manipulation

.NET is object oriented to the core. In fact, even ordinary variables are really full-fledged objects in disguise. This means that comman data types types have the built-in smart to handle basic operations. Even better, it means you can manipulate strings, dates, and numbers in the same way in C# or VB language.
As an example, every type in the .NET class library includes a ToString() method. The default implanation of this methos returns the class name. In simple variables, a more useful result is returned : the string representation of the given variables.
The following code snippet demonstrates how to use the ToString() method with an integer:
string VMyString;
int vMyInteger=100;
vMyString=vMyInteger.ToString();

Type Conversions

Converting information from one data type to another is a fairly common programming task.For example, you might retrieve text input for a user that contains numbers you want to use for a calculation.Or, you might need to take a calculated value and transform it into text you can display in a web page.
Conversion are two types: widening and narrowing.Widening conversion are always succeed.For example, you can convert a 32-bit integer into a 64-integer. You wont need any special code.

Here is an example:

int vMySmallValue;
long vMyLargeValue;
vMySmallValue=Int32.MaxValue;
vMyLargeValue=vMySmallValue;

Advanced Math Operations

Every language has its own set of keywords for common math operations such as rounding and trigonometry. In .NET languages, many of these keywords remain. However, you can also use a centralized Math class that's part of the .NET framework. This has the pleasant side effect of ensuring that the code you use to perform mathematical operations can easily be translated into equivalent statements in any .NET language with minimal fuss.
To use the math operations, you invoke the methods of the System.Math class. These method are static, which means they are always available and ready to use.

The following code snippet shows some sample calculations that you can perform with the math class:

double vMyValye;
vMyValue=Math.Sqrt(81);
vMyValue=Math.Round(42.889,2);
vMyValue=Math.Abs(-10);
VMyValue=Math.Log(24.212);
VMyValue=Math.PI;