Posts

Showing posts from June, 2010

Range Operator in Linq.

Image
Linq is almost providing all the functionalities and i have found one another great operator called range operator which will return a sequence of integer number from start point to number of count. Here is the signature of range operator in Linq.
public static IEnumerable<int> Range(int start, int count) Here the Start means the starting integer of the sequence and count means the number of sequence you want from starting integer. Let’s take a simple example for that where will print 5 to 9 sequence with the help of range operator. Here is the code for that.
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var RangeResult = Enumerable.Range(5, 5); Console.WriteLine("Range Result"); foreach (int num in RangeResult) { Console.WriteLine(num); } } } } And here is the output for that as …

Persisting row selection in data bound control like GridView,ListView

Image
Some times we need show large amount of data like hundred of rows but its very difficult to show that in a single web page so we are using the paging mechanism of inbuilt data bound control of .NET Framework like GridView and ListView. But in paging of data bound control its very hard to remember the row selection like suppose you have selected a row in page 1 and then you goto the page2 and return back to page1 the selected row will not be there. So to do that thing you have right custom coding for that. In Microsoft .NET Framework 4.0 there is one property called EnablePersistedSelection which will automatically do that task. It will first introduced on dynamic data support in .NET Framework 3.5 sp1 but its bye default supported by default in .NET Framework 4.0 it self. In earlier version of .net framework the selection was based on row index now its will be based data key for data bound controls. Here is the code for that.<asp:GridView id="PersitantGridView" runat=&qu…

Zip operator in Linq with .NET 4.0

Image
Microsoft .NET framework 4.0 is having many features that make developers life very easy. Its also provides some enhancement to Linq also. I just found a great operator called Zip which merge the sequence of two entities.Here is the explanation of Zip Operator from MSDN.“The method merges each element of the first sequence with an element that has the same index in the second sequence. If the sequences do not have the same number of elements, the method merges sequences until it reaches the end of one of them”.Here is the simple console application for the zip. I have taken three arrays for that one is string array, second one is integer array which is having same length as string array and third one is also integer array but having different length then string array. Here is the sample code for that.using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
str…

Sum and Concat Operator operators in Linq.

Image
Linq contains lots useful operators and i have found more two operators that can be help full in our day to day programming life. Here are explanation.Concat Operator: Concat operator concats two entities into single entities its very use full when we are doing some string operator where need to do string operations like concatenation. Here in example i have taken two arrays and concat into single entity. Sum Operator: When we are developing application like shopping cart and other stuff this operator can be use full where we need to calculate the total or order price and other stuff you can apply this operator array, list and anything that implemented IEnumerable interface. Here i have taken a integer array for the example.Here is the code for both operators.namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] a = { "a", "b", "c", "d" };
string[] b = { "d","e",&qu…

Take,Skip and Reverse Operator in Linq

Image
I have found three more new operators in Linq which is use full in day to day programming stuff. Take,Skip and Reverse. Here are explanation of operators how it works.Take Operator: Take operator will return first N number of element from entities.Skip Operator: Skip operator will skip N number of element from entities and then return remaining elements as a result.Reverse Operator: As name suggest it will reverse order of elements of entities.Here is the examples of operators where i have taken simple string array to demonstrate that.using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] a = { "a", "b", "c", "d" };


Console.WriteLine("Take Example");
var TkResult = a.Take(2);
foreach (string s in TkResult)
{
Console.WriteLine(s);
}

Console.WriteL…

Union,Except and Intersect operator in Linq

Image
While developing a windows service using Linq-To-SQL i was in need of something that will intersect the two list and return a list with the result. After searching on net i have found three great use full operators in Linq Union,Except and Intersect. Here are explanation of each operator.

Union Operator: Union operator will combine elements of both entity and return result as third new entities.

Except Operator: Except operator will remove elements of first entities which elements are there in second entities and will return as third new entities.

Intersect Operator: As name suggest it will return common elements of both entities and return result as new entities.

Let’s take a simple console application as a example where i have used two string array and applied the three operator one by one and print the result using Console.Writeline. Here is the code for that.

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { clas…

ASP.NET4.0-Compatibility Settings for rendering controls

Image
With asp.net 4.0 Microsoft has taken a great step for rendering controls. Now it will have more cleaner html there are lots of enhancement for rendering html controls in asp.net 4.0 now all controls like Menu, List View and other controls renders more cleaner html. But recently i have faced strange problem in rendering controls I have my site in asp.net 3.5 and i want to convert it in asp.net 4.0. I have applied my style as per 3.5 rendering and some of items are obsolete in asp.net 4.0. Modifying style sheet was a tedious job here asp.net 4.0 compatibility setting comes into help.Asp.net 4.0 compatibility settings provides full backward compatibility in terms of the rendering controls. You can assign this in your web.config section like following. <system.web>
<pages controlRenderingCompatibilityVersion="3.5|4.0"/>
</system.web>
Here the values of controlRenderingCompatibility is a string which will indicate on which way control should render in browser if y…

ASP.NET 4.0- CompressionEnabled Property in session state 4.0

Image
Hello Guys,This blog has been quite for few days. Because i was busy with some personal and professional work both and that’s why i am not able to work on writing blog posts which i have discovered in last few days. Here is one features of asp.net 4.0 that I am going to explain.As a web developer we all know about session. Without the use of session any database driven web application is incomplete. As we all know unlike windows form web forms are state less so when user interacts with web application we need to maintain state amongst web pages and we are using session for maintaining state between web pages for each users. ASP.NET is also provide same kind of session state functionalities. ASP.Net Session state identify request coming for same user and same browser for specific session time out interval and its preserves values in session for that specific time intervals and that’s help us in maintaining state amongst web pages for a specific user.ASP.NET Session state allows us to s…