Click here to Skip to main content
16,023,224 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
String strUIDNo;
            int count;
            int iRowCount = ds.Tables[0].Rows.Count - 1;

            if (iRowCount > -1)
            {
                strUIDNo = ds.Tables[0].Rows[iRowCount]["UIDNo"].ToString();
                //count=strUIDNo.Length
                count = Convert.ToInt16(strUIDNo.Substring(3));
                count++;
                txtNo.Text = "000" + count;

            }
            else
            {
                txtNo.Text = "0001";
            }




i Use this code for autogenerate of no..but this fail example if no is 11 it should show 0011 but in my code 00011.i want o/p like 0011 any other alternative
Posted

Use pad property of string in .net
 
Share this answer
 
Comments
Sandeep Mewara 20-Jun-12 8:39am    
Elaborate please!
I think you are generating id like 0001/0011/0111/1111 .

use this code:
C#
string strOutput = "";
int idLength = strUIDNo.Substring(3).Length;

if(idLength == 1)
 strOutput = "000" + count.ToString();
else if(idLength == 2)
 strOutput = "00" + count.ToString();
else if(idLength == 3)
 strOutput = "0" + count.ToString();
else
 strOutput = count.ToString();

then assign this value to your textbox.
txtNo.Text = strOutput;
 
Share this answer
 
v2
C#
txtNo.Text = string.Format("####",count);


OR

C#
txtNo.Text = string.Format("{0:d4}", count);


OR

C#
txtNo.Text =  count.ToString().PadLeft(4, '0');
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900