开发者

Textbox counter with another textbox counter [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

I have two textboxes "SerialNumber" and "SerialExtension". SerialNumber is auto generated starting with 1, which increases each time I click the "Add" button. The SerialExtension textbox has to have A,B, C,etc, concatenated with the SerialNumber value dispalyed each time I click the "Display" button. For that I gave a char counter. But each time the Seri开发者_运维知识库alNumber increases, my char counter does not reset from 'A'. Can anyone help me out? Code in C# please.

private static int counter = 1;
static char a = 'A';
  protected void Page_Load(object sender, EventArgs e)
    {
           txtSerialNo.Text = counter.ToString("0");
     }

protected void btnAdd_Click(object sender, ImageClickEventArgs e)
    {
          counter++;
        txtSerialNo.Text = counter.ToString("0");
     }

protected void btnDisplay_Click(object sender, ImageClickEventArgs e)
    {
          txtSerialextension.Text = txtSerialNo.Text + a.ToString();
          a++;
     }


How to assign values in C#: = Operator, works for char as well.


The reason that a does not start over with the value 'A' is that you will need to reassign that to a every time that it should be reset; there is no way for the program code to guess when this should happen. In your case, you want that to happen when you click btnAdd, so you need to add code for this in the click event handler for that button:

protected void btnAdd_Click(object sender, ImageClickEventArgs e)
{
    a = 'A'; // reset a to the value 'A'
    counter++;
    txtSerialNo.Text = counter.ToString("0");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜