Thursday, 24 May 2012

Adding Two text box value and redirecting it to third text box value

In design Page


 <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server" OnTextChanged="text2_changed" AutoPostBack="true"></asp:TextBox>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
    </div>
    </form>

In code behind


    protected void text2_changed(object sender, EventArgs e)
    {
        try
        {

            int x = Convert.ToInt32(TextBox1.Text);
            int y = Convert.ToInt32(TextBox2.Text);

            int z = x + y;

            TextBox3.Text = z.ToString();
        }
        catch (Exception ex)
        {
            Label1.Text = "There seems to be an Exception.  !!" + ex.ToString();
        }
    }





Wednesday, 2 May 2012

format for inner join SQL query

select columns
from table t1
inner join table t2 on t1.column1 = t2.column2
inner join table t3 on t1.column1 = t2.column2
where condition


example:

"Select a.ENTITYCODE,QUERYTYPEAFFID,b.tpaname,REQUESTTYPE,STATUS,QUERYTYPE from  STATUS_QUERY_TYPE_AFF a LEFT OUTER JOIN mastertpa b ON a.ENTITYCODE = b.TPACODE where a.ENTITYCODE=?"

Monday, 23 April 2012

Simple way to do the Paging in gridview

In aspx page:


 <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="true" PagerSettings-Mode="Numeric" PagerSettings-Position="TopAndBottom" PageSize="10" OnPageIndexChanging="GridView1_PageIndexChanging" >
       
        </asp:GridView>
    </div>
    </form>

In code behind:


protected void Page_Load(object sender, EventArgs e)
    {


        adddata();
    }


//Binding gridview


    public void adddata()
    {


        conn.Open();

        string strSQL = "Select * from LOGINDETAILS";

        OleDbCommand cmd = new OleDbCommand(strSQL, conn);

        DataSet ds = new DataSet();

        OleDbDataAdapter da = new OleDbDataAdapter(cmd);

        da.Fill(ds);

        GridView1.DataSource = ds;

        GridView1.DataBind();
        conn.Close();

    }


//paging index


    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)          
    {
        GridView1.PageIndex = e.NewPageIndex;
        adddata();
    }



output:


Biniding Gridview in asp .net

public void adddata()
    {


        conn.Open();

        string strSQL = "Select * from LOGINDETAILS";

        OleDbCommand cmd = new OleDbCommand(strSQL, conn);

        DataSet ds = new DataSet();

        OleDbDataAdapter da = new OleDbDataAdapter(cmd);

        da.Fill(ds);

        GridView1.DataSource = ds;

        GridView1.DataBind();

    }


Call this method in pageload.....
Thats it.......

Sunday, 22 April 2012

Coding structure that we use in Progamming Languages

With PascalCase, the first letter of every word in the identifier is upper case.

With camelCase, the first letter of the first word in the identifier is lower case, while the first letter of every subsequent word is uppercase.






Happy coding....... !!!!!

Friday, 13 April 2012

converting numeric values into words

In design part:

<form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server" Width="350px" ></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    </div>
    </form>

In code behind:

public partial class _Default : System.Web.UI.Page
{
    string Number;
    string deciml;
    string _number;
    string _deciml;
    string[] US = new string[1003];
    string[] SNu = new string[20];
    string[] SNt = new string[10];
    protected void Page_Load(object sender, EventArgs e)
    {
        Initialize();
    }

 
    protected void Button1_Click(object sender, EventArgs e)
    {
        string currency = "Rupees ";
        string _currency = " Paise Only";
        if (Convert.ToDouble(TextBox1.Text) == 0)
        {
            TextBox2.Text = "Null Value";
            return;
        }
        if (Convert.ToDouble(TextBox1.Text) < 0)
        {
            TextBox2.Text = "Invalid Value";
            return;
        }
        string[] no = TextBox1.Text.Split('.');
        if ((no[0] != null) && (no[1] != "00"))
        {
            Number = no[0];
            deciml = no[1];
            _number = (NameOfNumber(Number));
            _deciml = (NameOfNumber(deciml));
            TextBox2.Text = currency + _number.Trim() + " and " + _deciml.Trim() + _currency;
        }
        if ((no[0] != null) && (no[1] == "00"))
        {
            Number = no[0];
            _number = (NameOfNumber(Number));
            TextBox2.Text = currency + _number + "Only";
        }
        if ((Convert.ToDouble(no[0]) == 0) && (no[1] != null))
        {
            deciml = no[1];
            _deciml = (NameOfNumber(deciml));
            TextBox2.Text = _deciml + _currency;
        }

     
    }

    public string NameOfNumber(string Number)
    {
        string GroupName = "";
        string OutPut = "";

        if ((Number.Length % 3) != 0)
        {
            Number = Number.PadLeft((Number.Length + (3 - (Number.Length % 3))), '0');
        }
        string[] Array = new string[Number.Length / 3];
        Int16 Element = -1;
        Int32 DisplayCount = -1;
        bool LimitGroupsShowAll = false;
        int LimitGroups = 0;
        bool GroupToWords = true;
        for (Int16 Count = 0; Count <= Number.Length - 3; Count += 3)
        {
            Element += 1;
            Array[Element] = Number.Substring(Count, 3);

        }
        if (LimitGroups == 0)
        {
            LimitGroupsShowAll = true;
        }
        for (Int16 Count = 0; (Count <= ((Number.Length / 3) - 1)); Count++)
        {
            DisplayCount++;
            if (((DisplayCount < LimitGroups) || LimitGroupsShowAll))
            {
                if (Array[Count] == "000") continue;
                {
                    GroupName = US[((Number.Length / 3) - 1) - Count + 1];
                }


                if ((GroupToWords == true))
                {
                    OutPut += Group(Array[Count]).TrimEnd(' ') + " " + GroupName + " ";

                }
                else
                {
                    OutPut += Array[Count].TrimStart('0') + " " + GroupName;

                }
            }

        }
        Array = null;
        return OutPut;

    }

    private string Group(string Argument)
    {
        string Hyphen = "";
        string OutPut = "";
        Int16 d1 = Convert.ToInt16(Argument.Substring(0, 1));
        Int16 d2 = Convert.ToInt16(Argument.Substring(1, 1));
        Int16 d3 = Convert.ToInt16(Argument.Substring(2, 1));
        if ((d1 >= 1))
        {
            OutPut += SNu[d1] + " hundred ";
        }
        if ((double.Parse(Argument.Substring(1, 2)) < 20))
        {
            OutPut += SNu[Convert.ToInt16(Argument.Substring(1, 2))];
        }
        if ((double.Parse(Argument.Substring(1, 2)) >= 20))
        {
            if (Convert.ToInt16(Argument.Substring(2, 1)) == 0)
            {
                Hyphen += " ";
            }
            else
            {
                Hyphen += " ";
            }
            OutPut += SNt[d2] + Hyphen + SNu[d3];
        }
        return OutPut;
    }

    private void Initialize()
    {

        SNu[0] = "";
        SNu[1] = "One";
        SNu[2] = "Two";
        SNu[3] = "Three";
        SNu[4] = "Four";
        SNu[5] = "Five";
        SNu[6] = "Six";
        SNu[7] = "Seven";
        SNu[8] = "Eight";
        SNu[9] = "Nine";
        SNu[10] = "Ten";
        SNu[11] = "Eleven";
        SNu[12] = "Twelve";
        SNu[13] = "Thirteen";
        SNu[14] = "Fourteen";
        SNu[15] = "Fifteen";
        SNu[16] = "Sixteen";
        SNu[17] = "Seventeen";
        SNu[18] = "Eighteen";
        SNu[19] = "Nineteen";
        SNt[2] = "Twenty";
        SNt[3] = "Thirty";
        SNt[4] = "Forty";
        SNt[5] = "Fifty";
        SNt[6] = "Sixty";
        SNt[7] = "Seventy";
        SNt[8] = "Eighty";
        SNt[9] = "Ninety";
        US[1] = "";
        US[2] = "Thousand";
        US[3] = "Million";
        US[4] = "Billion";
        US[5] = "Trillion";
        US[6] = "Quadrillion";
        US[7] = "Quintillion";
        US[8] = "Sextillion";
        US[9] = "Septillion";
        US[10] = "Octillion";
    }
}


Output:




Thursday, 29 March 2012

simple and easy form validation using HTML 5 attribute



<table>
<tr>
    <td class="style1">
      <div align="left">Title<sup>*</sup></div>
    </td>
    <td>
      <div align="left">
          <asp:TextBox ID="TextBox1" runat="server"  required="required" ></asp:TextBox>
   
        </div>
    </td>
  </tr>

 <tr>
    <td class="style1">
      <div align="left"> Price<sup>*</sup>   </div>
    </td>
    <td>
      <div align="left"> <asp:TextBox ID="TextBox2" runat="server"  required="required"              pattern="[0-9]+$"  title="only numeric constants"></asp:TextBox></div>
    </td>
  </tr>
<tr>
<button runat="server"/>
</tr>

---------------------------------------------------------------------------------
thats it..................


we need use required="required' attribte of html5
and if we need to validate for specific constraint use pattern attribute just like regular expression validator
just like above second condition

<table>