13 November 2013

Automatically Generate the number and incremented in TextBox Field in C# and ASP.NET


// automatically generate the number and incremented in TextBox Field (C# and ASP.NET)


From Above Form,   " Praposal Number " TextBox field is automatically generate number incrementally in everytime process like 001,002.....so on.
                         
The Code is Shown Below...


using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;


protected void Page_Load(object sender, EventArgs e)
{
con.Open();
        SqlCommand cmd = new SqlCommand("SELECT COUNT(ProposalNumber) as Tot FROM Proposals", con);

        SqlDataReader dr;

        dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            int i = Convert.ToInt32(dr["tot"]);

            if (i > 0)
            {
                int j = i + 1;
                TextBox1.Text = "00" + j.ToString();

            }
            else
            {
                TextBox1.Text = "00";
            }

        }
        con.Close();


}

No comments:

Post a Comment