Oladotun Obileye

Oladotun Obileye

  • NA
  • 98
  • 19.3k

How to pass value from a control to another in C#

May 26 2019 5:10 PM
Good day everyone, please i am trying to count the number of records of a datagridview(dtuserpro) in a usercontrol profile and pass it to a label in another usercontrol dashboard but i get no value.
  1. public partial class userprofile : UserControl  
  2. {  
  3. private string count1;  
  4. public string Countt  
  5. {  
  6. get { return count1; }  
  7. set { count1 = value; }  
  8. }  
  9. public userprofile()  
  10. {  
  11. InitializeComponent();  
  12. }  
  13. SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\odt\Documents\Loanapp.mdf;Integrated Security=True;Connect Timeout=30");  
  14. DataTable dt = new DataTable();  
  15. private void profile_Load(object sender, EventArgs e)  
  16. {  
  17. int count = ((DataTable)this.dtuserpro.DataSource).Rows.Count;  
  18. lblcount.Text = count.ToString();  
  19. Countt = lblcount.Text;  
  20. }  
  21. private void dashboard_Load(object sender, EventArgs e)  
  22. {  
  23. userprofile up = new userprofile();  
  24. metroLabel1.Text = up.Countt;  
  25. }

Answers (7)