如何前四个字母 [英] how to first four letters
问题描述
名字:TextBox1
姓氏:TextBox2
提交(按钮)
-------------------------------
我要显示名字或姓氏的前四个字母和下滚动(_),计数应增加0001.插入新记录后计数应增加.
例如
名:Anil
姓氏:Singh
提交(按钮)
输出将显示Anil_0001
我希望显示它........
FirstName: TextBox1
LastName: TextBox2
Submit(Button)
-------------------------------
I want to display First four letters of firstname or lastname and underscroll(_) and count should be increase with 0001. after inserting new record count should be increase.
for example
FirstName: Anil
LastName: Singh
Submit(Button)
output will be shown Anil_0001
i want this should be displayed........
推荐答案
string firstName = "sudip";
string lastName = "saha";
Session["Count"] = 0;
if (firstName.Length > 3)
{
int count=Convert.ToInt32(Session["Count"]);
count++;
Session["Count"] = count;
str = firstName.Substring(0, 4);
str = str + "_" + count.ToString().PadLeft(4, '0');
}
对于计数,您需要将其存储在数据库中的某个位置.
您的代码会像这样,
Hi,
for the count you need to store it somewhere in database.
your code would be something like,
int count = getLastCount() + 1; //// get last inserted integer value.
string str = String.Format("{0}_{1}", TextBox1.Text.SubString(0,4), count.ToString("0000") );
您需要代码来从数据库中的getLastCount中获取最后插入的ID
希望这对您有帮助,
谢谢
-Amit.
you need code to get last inserted id from database in getLastCount
Hope this will help you,
Thanks
-Amit.
这篇关于如何前四个字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!