IT Forward
IT Forward

Reputation: 395

how to auto increment the number to increment by 1 after saving

I have a button which I want it to increment by one (1) every time I save. It must display on the label. I am struggling to get the correct format into the label so that it will get displayed every time you clicked save.

public void versionIncrement()
{
    count = Convert.ToInt32(lblOutput.Text.ToString()) + 1;
    lblOutput.Text = "1000" + count.ToString();
    lblOutput.Visible = true;
}

Upvotes: 0

Views: 429

Answers (2)

Felipe Oriani
Felipe Oriani

Reputation: 38598

You could have a private attribute into your form to store the value and increment on click event, for smaple:

// init in 1000 for sample
private int _outputValue = 1000; 

public void versionIncrement()
{
   _outputValue += 1; // increment 1
   lblOutput.Text = _outputValue.ToString();
   lblOutput.Visible = true;
}

Upvotes: 0

paul
paul

Reputation: 22001

int versionNumber = 1000;

public void versionIncrement()
{
    versionNumber++;
    lblOutput.Text = versionNumber.ToString();
    lblOutput.Visible = true;
}

Upvotes: 5

Related Questions