Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Friday, July 8, 2011

How to generate proxy class from a web service in asp .net?

open visual studio command prompt and go to root directory and write this command and press enter. MyProxyClass.cs will be created in your root directory.
WseWsdl3 http://hostServer/WebServiceRoot/WebServiceName.asmx?WSDL /out:MyProxyClass.cs

How to show sum at footer in Gridview.

Generally to show sum at footer in GridView we use. GridView's RowDataBound Event. We Create a variable(float/Int) outside of event.
and in RowDataBound Event we check row type. if row type is DataRow than we find the Cell's Text convert it into int and Add it to variable created outside of RowDataBound Event. and When RowType change from DataRow to Footer Row than we put that variable's value in footer.
But i want to tell you short and sweet method for it.
as all of you know generally we use DataTable as  datasource in gridview.
than we should use it
string str = dt.Compute("sum(sGrandTotal)", "").ToString();
now just find the Footer of gridview and put str variable in the cell. like this
grdReport.FooterRow.Cells[7].Text = "Total" + float.Parse(str).ToString( "N2");

Saturday, August 28, 2010

How to Convert Number in Indian Currency format(like lakh and crore format)?

A method to convert any number in indian curreny format in words.
public string NumberToText(int number)
    {

        if (number == 0) return "Zero";

        if (number == -2147483648) return "Minus Two Hundred and Fourteen Crore Seventy Four Lakh Eighty Three Thousand Six Hundred and Forty Eight";

        int[] num = new int[4];
        int first = 0;
        int u, h, t;
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        if (number < 0)
        {
            sb.Append("Minus ");
            number = -number;
        }

        string[] words0 = {"" ,"One ", "Two ", "Three ", "Four ", 
"Five " ,"Six ", "Seven ", "Eight ", "Nine "};

        string[] words1 = {"Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", 
"Fifteen ","Sixteen ","Seventeen ","Eighteen ", "Nineteen "};

        string[] words2 = {"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", 
"Seventy ","Eighty ", "Ninety "};

        string[] words3 = { "Thousand ", "Lakh ", "Crore " };

        num[0] = number % 1000; // units 
        num[1] = number / 1000;
        num[2] = number / 100000;
        num[1] = num[1] - 100 * num[2]; // thousands 
        num[3] = number / 10000000; // crores 
        num[2] = num[2] - 100 * num[3]; // lakhs 

        for (int i = 3; i > 0; i--)
        {
            if (num[i] != 0)
            {
                first = i;
                break;
            }
        }


        for (int i = first; i >= 0; i--)
        {
            if (num[i] == 0) continue;

            u = num[i] % 10; // ones 
            t = num[i] / 10;
            h = num[i] / 100; // hundreds 
            t = t - 10 * h; // tens 

            if (h > 0) sb.Append(words0[h] + "Hundred ");

            if (u > 0 || t > 0)
            {
                if (h > 0 || i == 0) sb.Append("and ");

                if (t == 0)
                    sb.Append(words0[u]);
                else if (t == 1)
                    sb.Append(words1[u]);
                else
                    sb.Append(words2[t - 2] + words0[u]);
            }

            if (i != 0) sb.Append(words3[i - 1]);

        }
        return sb.ToString().TrimEnd();
    }

Monday, August 23, 2010

What is partial Class in ASP .NET C-Sharp ?

Instead of defining an entire class, you can split the definition into multiple classes by using the partial keyword. When the application is complied, the C# complier will group all the partial classes together and treat them as a single class. There are a couple of good reasons to use partial classes. Programmers can work on different parts of a class without needing to share the same physical file. Also you can separate your application business logic from the designer-generated code

How to Create Dynamic Datatable ?

public Datatable DynamicDataTable
{
        DataTable dt = new DataTable();
        dt.Columns.Add("year", typeof(string));
        DataRow dr = null;
        for (int i = 2005; i <= DateTime.Now.Year; i++)
        {
            dr = dt.NewRow();
            dr["year"] = i.ToString() + "-" + (i+1).ToString().Substring(2);
            dt.Rows.Add(dr);
        }
return dt;
}