Actually I am pretty new to C#. I have two tables in database named as "Categories" and "MenuItems" respectively. What I want is when the form loads, I should get all Categories rows from the database and display them as text on dynamically generated buttons (number of buttons depends on the number of category rows), I have already accomplished it using following code: 

```
   private void Form1_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = "Data Source=Shezi;Initial Catalog=RMS;Integrated Security=True";
        SqlCommand cmd = new SqlCommand();
        con.Open();
        string commandText = "select Categories From Categories";
        cmd = new SqlCommand(commandText, con);
        SqlDataReader sdr = cmd.ExecuteReader();
        DataTable dt = new DataTable();
        dt.Load(sdr);
        con.Close();
        int btnName = 0;
        if (dt.Rows.Count>0)
        {
            btnName++;

            int PosY = 5;
            int rowCount = -1;
            int numOfRows = dt.Rows.Count;
            for(int i=0; i<numOfRows; i++)
            {
                rowCount++;
                foreach (DataRow row in dt.Rows)
                {
                    variables.btnText = dt.Rows[rowCount].Field<string>(0); 
                }
                Button button = new Button();
                button.Enabled = true;
                button.Text = variables.btnText;
                button.BackColor = Color.Green;
                button.ForeColor = Color.White;
                button.Width = 150;
                button.Height = 50;
                button.Name = "button" + btnName;
                button.Location = new Point(-2, PosY);
                button.Font = new Font("Georgia", 12);
                button.Click += Button_Click;
                panel.Controls.Add(button);
                PosY += 55;
            }
        }

    }

```

My Above code does generate dynamic buttons based on the category rows from database and here is my main problem, what I want is when a user clicks any of the dynamically generated buttons, the text of that button should be searched in menu items (obviously text of the button will be a category text), application should search that text in MenuItems rows and filter out all MenuItems that are saved against that category (For example if dynamically generated button had text "Burger", program should fetch all menu items from burger category and display then on more newly generated dynamic buttons) and similarly if button with category Cheese is clicked, it should fetch and create new dynamic buttons and populate Cheese menu items. 
This is what I have tried to get new dynamic buttons based on the buttons click so far: 

```
 private void btn1_Click(object sender, EventArgs e)
    {

        dt = manager.GetMenuItems(menuItems);
        var count = dt.Rows.Count;
        //int btnName = 0;

        int PosX = 160;
        int rowCount = -1;
        for (int i = 0; i < count; i++)
        {
            //btnName++;
            rowCount++;
            foreach (DataRow row in dt.Rows)
            {
                menuItems.MenuText = dt.Rows[rowCount].Field<string>(0);
                //categories.btnText = row.Field<string>("Categories", DataRowVersion.Original);//do not undo
                DataView dv = dt.DefaultView;
                dv.RowFilter = "MenuItem = MenuItem";
                DataTable dt1 = dv.ToTable();
                menuItems.MenuText = dt1.ToString();
            }
            //string btnText = count.ToString();
            Button btn1 = new Button();
            btn1.Enabled = true;
            btn1.Text = menuItems.MenuText;

            btn1.BackColor = Color.Navy;
            btn1.ForeColor = Color.White;
            btn1.Width = 150;
            btn1.Height = 50;
            btn1.Name = "btn1";

            btn1.Location = new Point(PosX, 10);
            btn1.Font = new Font("Georgia", 12);
            btn1.Click += new EventHandler(btn1_Click);
            pnlCategories.Controls.Add(btn1);
            PosX += 150;

            //var newvalue =  ds.Tables[0].Rows[1].ItemArray[0].ToString();    

        }

    }

```

I have searched many ways but couldn't find anything similar, I have tried different threads on stackoverflow too but no luck, need help!