Please solve this problem i am new to asp.net programming 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class NewUser : System.Web.UI.Page
{



    protected void Page_Load(object sender, EventArgs e)
    {




    }
    protected void TextBox4_TextChanged(object sender, EventArgs e)
    {

    }
    protected void NewUser_submit_btn_Click(object sender, EventArgs e)
    {
        //try
        //{
            SqlConnection con = new SqlConnection("data source=user\\sqlexpress;" +
                "Initial Catalog=TestDB;" +
                "Integrated Security=SSPI");

            string sql = "INSERT INTO employee VALUES(@empid,@name,@desig,@skill,@teamid,@mgrid,'"+TextBox5.Text+"','"+TextBox6.Text+"','" +TextBox7.Text+ "','"+TextBox8.Text+"',"+TextBox9.Text+","+TextBox10.Text+",'"+TextBox11.Text+"','"+TextBox12.Text+"','"+TextBox13.Text+"')";

            using (SqlCommand com = new SqlCommand(sql, con))
            {

                com.Parameters.AddWithValue("@empid", TextBox1.Text);//Employee ID
                com.Parameters.AddWithValue("@name", TextBox2.Text);
                com.Parameters.AddWithValue("@desig", TextBox3.Text);
                com.Parameters.AddWithValue("@skill", TextBox4.Text);
                com.Parameters.AddWithValue("@teamid", DropDownList1.SelectedValue);
                com.Parameters.AddWithValue("@mgrid", "");   //when I entring values in employee id textbox  that value should be added there in dropdownlist2 and it should be displayed at every time
            }


        }
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {


    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }
}

Are you saying that after entering the data (employee ID) that it should be saved to the database and then the next time the app is started dropDownList2 is populated with the employee IDs? If so, then the dropDownList2 will need to draw the info out of the database and have the data added to it, presumably on page_load.
Are you having trouble with the data insertion or getting it back out?

No. I will give an example. For the first time i am entering first record 1001(empid) at the same time it should be displayed in dropdownlist2 too. for the second time record is 1002(empID) at the same time it should display both(ie,1001,1002)values.like that....

And there is a problem with insertion to the database.

OK, if you want the dropdownlist2 to show the newly entered data and everythign before it then then best thing to do is what I suggested above.
1) insert the employee ID into the database
2) on page_load (or call it directly after the insertion) draw the employee info from the database and populate the dropdownlist
2a) You could, instead of hitting the database each time the page reloads, fill the list the first time the page loads and everytime you save an employee ID just add it to the list with

dropdownlist2.Items.Add('the employee ID')

That will save a bit of server resources and data passing back and forth.

As for the insertion problem, tell us what it is and post up some code, we'll have a look.

Sorry. not understood. Can u modify that in above code...

after the database insertion has completed the simplest thing you can do is this:

dropdownlist2.Items.Add(TextBox1.Text);

Or, better, code up another function that selects the employee ID out of the database and adds the resulting dataset to dropdownlist2. You need to do this anyway if you intend to populate the dropdown when the form loads.

Thanks....Its Worked...

dropdownlist2.Items.Add(TextBox1.Text);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.