Click here to Skip to main content
15,884,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In database records as follows


Room Course

11 EFA

12 RFA

13 MFA

14 ROC



Gridview as follows


Room Course


11 Button1

12 Button2

13 Button3

14 Button4


for each room i place the Button inside the gridview, when i click the each Button i want to pop up the dropdownlist,in that dropdownlist values are to be retireved from the database. for each room course are assigned that i mentioned as above.


so when i click the button display the dropdownlist,select the course that course to be postion into the partiuclar room in the gridview.


for that how can i do using csharp.

Rgds,
Narasiman P.
Posted

1 solution

try this
C#
private void dataGridView1_CellClick_1(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == dataGridView1.Columns["Column2"].Index && e.RowIndex >= 0)
            {
                //MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
                OleDbConnection con=new OleDbConnection("YourConnectionString");
                string str = "select * course from YourTableName where room='" + dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString() + "'";
                OleDbCommand cmd = new OleDbCommand(str, con);
                OleDbDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    dr.Read();
                    MessageBox.Show(dr[0].ToString());
                }

            }
        }
 
Share this answer
 
v2

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