I have form empdetails like this
EmpId:textbox Name:textbox
username:textbox Password:textbox
I need to generate empid and it start with 0001 and display it in the empid field and all other information will be entered employee and i have provided save button when the user clicks on it it should be saved in the db and next time when the user clicks on this form it should display empid as 0002 and the process continues.When the user clicks on the save button it should be saved in the db and it should display in the gridview with id and name field made it as hyperlink it should look like this.
ID Name
0001 Sweety
Can any1 help me on this
With Regards,
Sweety

Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 29, 2011, 2:17 AM EDT
Run the attachments.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
int count;
protected void Page_Load(object sender, EventArgs e)
{
autoincrement();
bindgrid();
}
protected void btn_insert_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "insert into employee values('" + txt_empid.Text.Trim() + "','" + txt_empname.Text.Trim() + "'," + txt_sal.Text.Trim() + ")";
com = new SqlCommand(str, con);
com.ExecuteNonQuery();
con.Close();
Label4.Text = "Records successfully Inserted";
bindgrid();
txt_empid.Text = "";
txt_empname.Text = "";
txt_sal.Text = "";
autoincrement();
}
void bindgrid()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from employee";
com = new SqlCommand(str, con);
SqlDataReader reader;
reader = com.ExecuteReader();
g1.DataSource = reader;
g1.DataBind();
con.Close();
}
void autoincrement()
{
SqlConnection con = new SqlConnection(strConnString);
str = "select count(*) from employee";
com = new SqlCommand(str, con);
con.Open();
count = Convert.ToInt16(com.ExecuteScalar()) + 1;
txt_empid.Text = "000" + count;
con.Close();
}
}
Thanks
Sweety45 reputationPosted Sep 29, 2011, 3:23 AM EDT
Krishna GaradRank #191 · 12.8K reputationPosted Sep 29, 2011, 3:52 AM EDT
Select Max(Empid+1) From TableName
And show this value in your textbox while inserting you can insert now this empid also with other records.