Wednesday 22 April 2015

How find the HCF of any given two number in c# asp.net ?


Here I written a C# Program to Finds and Display the H.C.F of a Given Number. In other words the H.C.F is the largest of all the common factors.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
          
            int num1,num2,i;
            int hcf =0;
            Console.Write("\n Please Enter the First Number : ");
            num1 = int.Parse(Console.ReadLine());
            Console.Write("\n Please Enter the Second Number : ");
            num2 = int.Parse(Console.ReadLine());
            for(i=1;i<=num1||i<=num2;++i)
            {
                if(num1%i==0 && num2%i==0)
                {
                    hcf=i;
                }
            }    
            Console.Write("\nThe Common Factor (HCF) is : ");
            Console.WriteLine(hcf);
            Console.Read();
        }
        
    }
}

Output :-



OnHtmlDataCellPrepared example of ASPxGridView


ASPxGridView Source Code

Here is ASPxGridView which  implements the OnHtmlDataCellPrepared event.

<dx:ASPxGridView ID="gvEmp" AutoGenerateColumns="False" runat="server" 
            OnHtmlDataCellPrepared=" gvEmp_HtmlDataCellPrepared">
            <Columns>
                <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0">
                </dx:GridViewCommandColumn>
                <dx:GridViewDataTextColumn FieldName="fldFirstName" VisibleIndex="1">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="fldLastName" VisibleIndex="2">
                </dx:GridViewDataTextColumn>
                 <dx:GridViewDataTextColumn FieldName="fldMobileNo" VisibleIndex="3">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="fldEmailAddress" VisibleIndex="4">
                </dx:GridViewDataTextColumn>
                 <dx:GridViewDataTextColumn FieldName="fldSalary"  VisibleIndex="5">
                </dx:GridViewDataTextColumn>
 <dx:GridViewDataTextColumn FieldName="fldEmpId"  VisibleIndex="6">
                </dx:GridViewDataTextColumn>
            </Columns>

        </dx:ASPxGridView>




Here is a event method called gvEmp_HtmlDataCellPrepared which change the color of cell fldSalary if cell value is grater then 100000.

protected void gvEmp_HtmlDataCellPrepared(object sender,
    DevExpress.Web.ASPxGridViewTableDataCellEventArgs e) {
    if (e.DataColumn.FieldName != "fldSalary") return;
    if (Convert.ToInt32(e.CellValue) > 100000)
        e.Cell.BackColor = System.Drawing.Color.green;
}