Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I have a list of employees in dropdownlist.
I have employee table in database.

if user select an employee from dropdown am binding data of that selected emp in gridview.
Now i wants to update the info of the particular selected user in gridview,How can i update
Posted

Hi . Just add following code to your application to Update data gridview on index changed event of drop down list.

C#
void UpdateGrid()
    {
       
        // Open connection
        using (SqlCeConnection c = new SqlCeConnection("ConnectionString"))
        {
        c.Open();
        // 2
        // Create new DataAdapter
        using (SqlCeDataAdapter a = new SqlCeDataAdapter("SELECT * FROM table WHERE empID="+EmpId, c))
        {
            // 3
            // Use DataAdapter to fill DataTable
            DataTable t = new DataTable();
            a.Fill(t);
            // 4
            // Render data onto the screen
            dataGridView1.DataSource = t;
        }
        }
    }

Kindly revert if you have any issues..
 
Share this answer
 
v2
 
Share this answer
 
v2
 
Share this answer
 

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