Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
there are 50 text boxes in my code. i want to update only the edited text box values in sql. Is there any code in c# to find how many text box values user has edited out of 50?
Posted 4-Feb-13 0:59am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

No. The easiest way is to use the Tag property. Set all of your textboxes Tags to either a false, or the starting string, and then:
If you use the Tag as a bool, handle the Textboxes.TextChanged Event and set them all to the same method:
private void MyTextBoxes_TextChanged(object sender, EventArgs e)
    TextBox tb = sender as TextBox;
    if (tb != null)
        tb.Tag = true;
You can then look at the tags when you save and decide if it needs to be updated.
If you use a string, then just compare the current value against the Tag value and only save if different.
Why are you using 50 textboxes? Wouldn't a grid of some form be a better solution?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 315
1 Jochen Arndt 190
2 DamithSL 125
3 PIEBALDconsult 110
4 Garth J Lancaster 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195

Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100