在窗口中自动生成不像0011的 [英] autogenerate no like 0011 in window

查看:65
本文介绍了在窗口中自动生成不像0011的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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";
            }





我使用此代码自动生成no ..但此失败示例如果no为11,则应显示0011,但在我的代码00011中.我想像0011一样使用o/p其他任何替代方法





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

推荐答案

txtNo.Text = string.Format("####",count);







OR

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







OR

txtNo.Text =  count.ToString().PadLeft(4, '0');


我认为您正在生成ID,例如0001/0011/0111/1111. br/>
使用此代码:
I think you are generating id like 0001/0011/0111/1111 .

use this code:
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;


在.net中使用字符串的pad属性
Use pad property of string in .net


这篇关于在窗口中自动生成不像0011的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆