如何在表格上生成自动编号 [英] how to generate autonumbers on form

查看:430
本文介绍了如何在表格上生成自动编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关生成自动编号以填写表格上数据的帮助.

我有10个文本框和一个按钮,当我在每个文本框中写入数据并单击按钮时,所有这些数据都已添加到绑定表中.但其中一个排除的文本框用于生成自动编号,或者我想这样
设置这些自动编号的形式应如下所示

当前year_number

例子
2011_13
2011_14
.......

I need help with generating autonumbers for filling in data on the form.

I have 10 textboxes and one button, when I write in data in each of those textboxes and click button then all those data have been added to binded table. but one excluded textbox is for generating autonumbers or I wanna it to be that way
the form for making these autonumbers should be like this

current year_number

example
2011_13
2011_14
.......

推荐答案

这怎么可能是个问题?您可以从System.DateTime.Now知道年份,月份等.

请参阅 http://msdn.microsoft.com/en-us/library/system.datetime.aspx [^ ] .

-SA
How come it can be a problem? You know the year, month, etc. from System.DateTime.Now.

See http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

—SA


在处理点击事件时...

when handling the click event...

int newVal = 0;

if (textbox.text != string.empty)
{
   string lastValStr = textbox.text.substring(5);
   if (Int.TryParse(lastValStr, out newVal))
      newVal++;
}

textbox.text = String.Format("{0}_{1}", DateTime.Now.Year, newVal);


这篇关于如何在表格上生成自动编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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