We help IT Professionals succeed at work.

Display counting in a textbox

Peter Kiers
Peter Kiers asked
on
Hi,

I have a button and a textbox on my form.
What I want is when I click on the button a '1' must be displayed in the textbox
When i click again a '2' must be displayed, When i click again a '3' must be displayed etc.. etc...
How can I do that?

Peter

Comment
Watch Question

AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
at form level
Int32 i = 0;

When the form is initialised
txtBox.Text = "0";

In the button event
i++;
txtBox.Text = i.ToString();

Commented:
<script language=JavaScript>
< !--
function ChangeValue() {
document.MyForm.MyTextbox.value = parseInt(document.MyForm.MyTextbox.value) +1;
}
-->
< /script>
<form name="MyForm" action="http://www.example.com" method=post>
 < input type="text" name="MyTextbox" value="0">
 < input type="button" name="btnclck" value="Click Me" onclick="javascript:ChangeValue();" >
< /form>
Peter KiersOperator

Author

Commented:
In the integer called counter1 there has to count 1 up every time the user presses the button
How can I do that?
private void button1_Click(object sender, EventArgs e)
        {
            int counter1 = (int)numericUpDown1.Value;
            int counter2 = (int)numericUpDown2.Value;
            System.Data.DataRow row = gridView1.GetDataRow(gridView1.FocusedRowHandle);
            string myName = row[0].ToString();
            string myServSize = row[1].ToString();
            string myCal = row[2].ToString();
            string myProt = row[3].ToString();
            string myCarbs = row[4].ToString();
            string mySod = row[5].ToString();
            string myFib = row[6].ToString();
            string myFat = row[7].ToString();
            string myChol = row[8].ToString();


            textBox1.Text += "<Node Id=" + counter1 + " ParentId=" + counter2 + ">" + "\r\n" +  <===================
            "<NodeData>" + "\r\n" +
            "<Cell xsi:type=xsd:string>" + myName + "</Cell>"+"\r\n" +
            "<Cell xsi:type=xsd:string>" + myServSize + "</Cell>"+"\r\n" +
            "<Cell xsi:type=xsd:string>" + myCal + "</Cell>"+"\r\n" +
            "<Cell xsi:type=xsd:string>" + myProt + "</Cell>"+"\r\n" +
            "<Cell xsi:type=xsd:string>" + myCarbs + "</Cell>"+"\r\n" +
            "<Cell xsi:type=xsd:string>" + mySod+ "</Cell>"+"\r\n" +
            "<Cell xsi:type=xsd:string>" + myFib + "</Cell>"+"\r\n" +
            "<Cell xsi:type=xsd:string>" + myFat + "</Cell>"+"\r\n" +
            "<Cell xsi:type=xsd:string>" + myChol + "</Cell>"+"\r\n" +
          "</NodeData>"+"\r\n" +
         "</Node>" + "\r\n";
        }

Open in new window

AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
           int counter1 = (int)numericUpDown1.Value + 1;
            int counter2 = (int)numericUpDown2.Value + 1;  //maybe you don't want this step
Freelance programmer / Consultant
CERTIFIED EXPERT
Commented:
ps.
Obviously the value of numericUpDown1 isn't changed - are you asking the right question?


pps.
numericUpDown1.Value = (int)numericUpDown1.Value + 1;
Peter KiersOperator

Author

Commented:
Thanks it works.
AndyAinscow gave the right solution.

Greetings,

Peter Kiers

Explore More ContentExplore courses, solutions, and other research materials related to this topic.