如何在用户点击插入后每次在文本框中生成自动编号 [英] how to generate auto number in textbox every time after user click on insert after
问题描述
PLZ帮助我在我的项目中如何在填写值,,,,,,用户点击插入按钮后文本框可以生成自动增量编号,我需要像C1,C2等格式的序列值....请帮助我
plz help me in my project how text box can generate auto increment number when user click on insert button after filling values,,,,,,i need sequtenial values in format like C1,C2, and so on....kindly plz help me
推荐答案
在后面的代码中创建一个字段_nextNumber
来存储下一个数字和然后在按钮单击处理程序中将文本框的文本设置为C+ _ nextNumber
然后增加_nextNumber
make a field_nextNumber
, in your code behind, to store the next number and then in your button click handler you set the text of the textbox to"C"+_nextNumber
and then increment_nextNumber
你可以概括地使用这两种方法中的任何一种。
1.创建一个如下所示的静态类
You can problably use any one of the two approaches.
1. Create a static class like below
public static class SequentialNumber
{
private static int _currentNumber=0;
public static string GetNextNumber()
{
_currentNumber++;
return "C"+_currentNumber.ToString();
}
}
然后在插入按钮中单击,编写如下代码以获取文本框中的序列号
and then in insert buttons click, write a code like below to get the sequential number in the text box
string ContractNo=SequentialNumber.GetNextNumber();
2方法。
在页面后面的代码中声明变量_currentnumber
$ b插入按钮的click事件中的$ b编写如下代码。
2 approach.
Declare a variable _currentnumber in the code behind page
in the click event of the insert button write code as below.
if(string.IsNullOrEmpty(ViewStatte["Num"]))
_currentNumber=0;
else
{
_currentNumber=(int)ViewState["Num"];
}
_currentNumber++;
ViewState["Num"]=_currentNumber;
string ContractNo=_currentNumber;
方法1可用于所有类型的项目,其中方法2仅可用于asp.net。
希望这会有所帮助。
--sunil
Approach 1 can be used in all types of project where as approach 2 can be used in asp.net only.
Hope this helps.
--sunil
嗨希望这会对你有所帮助
Hi hope this will help You
public void Method()
{
Connection();
int Num1 = 0;
cmd = new SqlCommand("Select MAX(Column) from TableName", cs);
dr = cmd.ExecuteReader();
while (dr.Read())
{
Num1 = int.Parse(dr[0].ToString());
}
dr.Close();
TextBox.Text ="C" + (Num1 + 1).ToString();
cs.Close();
}
这篇关于如何在用户点击插入后每次在文本框中生成自动编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!