数字循环获取行号(01,02,03)

时间:2016-11-22 02:32:48

标签: c#

string[] SName = Request.Form.GetValues("Description");
string[] Email = Request.Form.GetValues("Email");
DataTable dtable = dt();
for (int i = 0; i <= SName.Length - 1; i++)
{
    DataRow row1 = dtable.NewRow();
    row1["Description"] = SName[i];
    row1["Email"] = Email[i];
    DAL.DMSS insertdata = new DMSS();
    insertdata.INSERT_DATA(loggeduser.SUBSIDIARY_CD, input, SName[i], Email[i]);
}

以上是我从动态行添加数据的代码。 如果我有2行,我得到的数据是:

enter image description here

现在我想再添加1个数据,序列号

enter image description here

尝试了这段代码但没有工作..

  for (int i = 0; i <= SName.Length - 1; i++)
        {
            if (i.length <2 )
            {
               string strvalue = i.PadLeft(2, '0');
            }
            else
            {
                string strvalue = i;
            }

            DataRow row1 = dtable.NewRow();
            row1["Description"] = SName[i];
            row1["Email"] = Email[i];
            DAL.DMSS insertdata = new DMSS();
            insertdata.INSERT_DATA(loggeduser.SUBSIDIARY_CD, input, SName[i], Email[i], strvalue);
        }

1 个答案:

答案 0 :(得分:2)

        for (int i = 0; i <= SName.Length - 1; i++)
        {
            var rowNumber = (i + 1).ToString("0#");
        }