Click here to Skip to main content
15,942,449 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi, I am New to this subject. i hope someone will help me to do this task
Autopopulate text in textbox depending on selected value from dropdownlist
Thanks in advance................................
I wrote this code for Drop Down and i want the auto generated value show in text box

eg.E153 is last no. and new employee is joined to organization. i want to add him,the EmpCode must be auto generated in test box as E154.........


SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = " SELECT EmpType_code FROM [systbl_EmpType] order by EmpType_code";
cmd.Connection = con;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
ddlType.DataSource = ds;
ddlType.DataTextField = "EmpType_code";
ddlType.DataValueField = "EmpType_code";
ddlType.DataBind();
ddlType.Items.Insert(0, new ListItem("Please select", "NA"));
return ds;
}

protected void btn1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("SELECT MAX(EmpCode) from prl_EmployeeMaster WHERE EmpCode LIKE '[ddlType.SelectedItem.Value]%'");
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();

double count;
con.Open();
count= Convert.ToDouble(cmd.ExecuteScalar())+1;
da.Fill(ds);
txt1.Text = (ddlType.SelectedItem.Value) + count;
ddlType.DataSource = ds.Tables[0];
ddlType.DataBind();
cmd.ExecuteNonQuery();
con.Close();
Posted
Updated 18-Jun-15 1:09am
v3
Comments
Thanks7872 18-Jun-15 4:42am    
1) Follow guidelines displayed on left pane when posting question
2) Provide enough detail and show the effort what have you tried so far.
Member 11769503 18-Jun-15 4:44am    
hi, actually am working on c# and i will show upto wt i did.....
Thanks7872 18-Jun-15 4:47am    
Use improve question link at bottom of the question to add details. Point out the exact problem.
Member 11769503 18-Jun-15 6:54am    
This is the code i wrote for dropdown and i want that autp geration in textbox in C# coding
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = " SELECT EmpType_code FROM [systbl_EmpType] order by EmpType_code";
cmd.Connection = con;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
ddlType.DataSource = ds;
ddlType.DataTextField = "EmpType_code";
ddlType.DataValueField = "EmpType_code";
ddlType.DataBind();
ddlType.Items.Insert(0, new ListItem("Please select", "NA"));
return ds;
Thanks7872 18-Jun-15 6:57am    
Dont you read the comment? I already told you to post code using "Improve question" link. Do you have any specific problems following guidelines?

1 solution

As per my understanding,

Step 1: Get the name/Value
JavaScript
var name = $('#dropdownId' option:selected).val(); //$('#dropdownId' option:selected).text();


Step 2: Append it into text box.
JavaScript
$('#textboxId').val(name);


Step 3:

Keep the above code (step 2) inside document.Ready(function)/On load/Next button click in case of Wizard.

Please accept the solution if this helps otherwise give exact scenario so that we can find some solution.
 
Share this answer
 
v2
Comments
Pradip Kumar Sen 18-Jun-15 10:16am    
The above answer I gave based on his previous un-edited question. :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900