How to implement LINQ Concepts with Aggregate operators in asp.net

By
Hi Friends ! Today , i will show you "How to implement LINQ Concepts with Aggregate operators in asp.net". The Aggregate operators are used to calculate a value. Here  i will show you the values of all aggregate functions in List Box Control.This Aggregate functions are basically used in database values manipulation. I have already used this concepts in sql server database. There are some aggregate operators are used in asp.net as given below:-
  • Count
  • Min
  • Max
  • Average
  • Aggregate
You can use this aggregate operators concepts in your Real time projects if it needed.There are some steps to implement this concepts in your asp.net application as given below:-
 Step 1 : - First open your visual studio -->File -->New -->website --Select ASP.NET Empty website -->ok -->Open Solution Explorer -->Add a New web form (Default .aspx) -->Drag and Drop List box and Button's controls on the form as given below:-
web_form


Step 2 : -  Now Write the c# codes on submit Button Clicks(default.aspx.cs page) as given below:-
using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int[] num = { 1, 2, 4, 6, 8, 9, 10, 12, 22, 55, 67, 87, 56, 86, 89, 88, 20, 100, 120, 140, 121, 131, 256, 90 };
        int even_num = num.Count(a => a % 2 == 0);
        ListBox1.Items.Add("Count of even numbers = " + even_num);
        int min_num = num.Min();
        ListBox1.Items.Add("Minimum Numbers = " + min_num);
        int max_num = num.Max();
        ListBox1.Items.Add("Maximum Numbers = " + max_num);
        int odd_num = num.Count(b => b % 2 == 1);
        ListBox1.Items.Add("Count of Odd numbers= " + odd_num);
        int all_sum = num.Sum();
        ListBox1.Items.Add("Count of Odd numbers= " + odd_num);
        double average = num.Average();
        ListBox1.Items.Add("The average of all numbers= " + average); ;
    }
}

Step 3 : - Now Run the Application(Press F5) --> Press Submit Button -->You will see the following output as given below:-


web_output

Note:- Here ,i have displayed the output values in List box control .You can display it in Drown list and other controls also.

Download Whole Application 
     Download

0 comments:

Post a Comment

Powered by Blogger.