How To Auto No Generate in C# asp.Net Project

How To Auto No Generate in C# asp.Net Project

We need the auto Generate No in our Asp.net Project and our need is my project no is used first digit  like my ProjCode is - 10001 then my my auto generate no is  Serial No is -10000001 its my need so i can do this my web pages
Its a Solution of my This Problem .
Coding ......

We have using the a drop-down list  than selecting a project code and out put is show a textbook in a web pages.

HTML 
Serial No#</label>
<asp:TextBox ID="TextBox1" onKeyPress="return checkIt(event)" 
                                runat="server" AutoPostBack="True" 
                                        class="form-control" ontextchanged="TextBox1_TextChanged"  
                                        placeholder="Serial No" ReadOnly="True"></asp:TextBox>
                            &nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                ErrorMessage="*" ControlToValidate="TextBox1" ForeColor="Red"></asp:RequiredFieldValidator>            


  Project #</label>
                        <asp:DropDownList ID="DropDownList1" runat="server" class="form-control" AutoPostBack="True" 
                            onselectedindexchanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>


Its CS Code

   Page Lode Events 

 if (!IsPostBack)
        {

           
            autogenerated();

        }
// its a function then generate a auto no.

 void autogenerated()
    {
        string connection = ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString;
        SqlConnection con = new SqlConnection(connection);
        str = "select count(*) from ProjectsH";
        com = new SqlCommand(str, con);
        con.Open();
        count = Convert.ToInt16(com.ExecuteScalar()) + 1;
         
// its major line of code the using it you need the select Last  four digit.
        string creditNumber = DropDownList1.SelectedItem.ToString(); 
        var mukesh4 = creditNumber.Substring(creditNumber.Length -4, 4);


// its a code select your first digit in the dropdown list.
        string input = DropDownList1.SelectedItem.ToString();
        string mukesh5 = input.Substring(input.Length -5, 1); 



       TextBox1.Text = mukesh5+"00" +mukesh4; 
        con.Close();


    }
    
Out 'put is -select valve is 10001 then out put is 10000001.

Thanks 



Post a Comment

Previous Post Next Post

Design a beautiful Login/Signup (with google map) in Flutter | Flutter UI | VS Code | iOS Android