Gabriel olayinka

Gabriel olayinka

  • NA
  • 119
  • 4.2k

creating controls in c#

Apr 4 2018 2:11 AM
i"m creating LinkLabel control using database value... this is working fine ....
but why is it that the event handler i assigned to different controls are only show the same thing .... not different actions ... thanks... here is my code
  1. void createControls()  
  2. {  
  3. try  
  4. {  
  5. con.Open();  
  6. // Read specific values in the table.  
  7. SqlCommand cmd = new SqlCommand("select * from PAGES ", con);  
  8. SqlDataAdapter da = new SqlDataAdapter(cmd);  
  9. ds = new DataSet();  
  10. da.Fill(ds, "CLASSROOMS");  
  11. for (count=0; count <= ds.Tables[0].Rows.Count - 1; count++)  
  12. {  
  13. CLASS_NAME = ds.Tables[0].Rows[count]["CONTROL_NAME"].ToString(); // rdr.GetString(3);  
  14. CONTROL_TYPE = ds.Tables[0].Rows[count]["CONTROL_TYPE"].ToString(); // rdr.GetString(2);  
  15. CONTROL_TEXT = ds.Tables[0].Rows[count]["CONTROL_TEXT"].ToString() + "(" + NUMBER_PER_CLASS + ")";  
  16. CONTROL_LOCATION = (int)ds.Tables[0].Rows[count]["CONTROL_LOCATION"];  
  17. CONTROL_HEIGHT = (int)ds.Tables[0].Rows[count]["CONTROL_HEIGHT"];  
  18. CONTROL_NAME = ds.Tables[0].Rows[count]["CONTROL_NAME"].ToString();  
  19. LinkLabel lk = new LinkLabel();  
  20. Controls.Add(lk);  
  21. lk.Text = CONTROL_TEXT;  
  22. lk.Location = new Point (CONTROL_HEIGHT,CONTROL_LOCATION);  
  23. lk.Name = CONTROL_NAME;  
  24. lk.AutoSize=true;  
  25. lk.Click += (s,e)=> { MessageBox.Show(CONTROL_NAME.ToString()); };  
  26. lk.Show();  
  27. }  
i want a messageBox to pop up and show the control Name once the control is clicked...... but i"m getting the same Control name for all the controls

Answers (2)