How to call serial one by one when enter text box
I am using 4 text box. One for household ID,Second is Serial no,Third is Name, Fourth is Sex. I have one database where Household and other information entered. I will just put the household ID then serial no 01 will be shown after that 02 and so on. When serial 01 display then Name and sex is displaying. after that I will click save button then it will add then Household ID will be read only and serial number will be display one after another. How I will do. Please help me.
PRASANTA BISWASPosted Jan 22, 2014, 10:08 AM
Hh Slno Name Sex
S0010001 01 A Male
S0010001 02 B female
S0010001 03 C Male
So, When I will put Hh then Slno 01 will be the show automatically into txtSlNo.Text box. After that Hh will disbale and slno 02 will be appear if I press enter after that serial 03 like that. Other variable will show automatically.
Anubhav ChaudharyPosted Jan 22, 2014, 6:48 AM
Anubhav ChaudharyPosted Jan 22, 2014, 6:47 AM
It's really difficult to understand your problem but I am making a guess that you want to bind a DropDown List to your Database, in this dropdown "household ID" will be shown and as you select any of the ID than related data will be shown in the other Textboxes. If this is the problem then you can use this code:
SqlConnection x;
SqlCommand y;
SqlDataReader z;
SqlDataAdapter y1;
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
x = new SqlConnection(@"data source=AGILE-A4D936161\SQLEXPRESS;integrated security=sspi;initial catalog=master");
x.Open();
if (!Page.IsPostBack)
{
y1 = new SqlDataAdapter("select empno from emp", x);
dt = new DataTable();
y1.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "empno";
DropDownList1.DataBind();
}
x.Close();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
x.Open();
y = new SqlCommand("select * from emp where empno=" + DropDownList1.SelectedItem.Text, x);
z = y.ExecuteReader();
while (z.Read())
{
TextBox2.Text = z[1].ToString();
TextBox3.Text = z[2].ToString();
}
x.Close();
}