Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

Display counting in a textbox

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

Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

at form level
Int32 i = 0;

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

In the button event
i++;
txtBox.Text = i.ToString();
<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>
Avatar of Peter Kiers

ASKER

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

           int counter1 = (int)numericUpDown1.Value + 1;
            int counter2 = (int)numericUpDown2.Value + 1;  //maybe you don't want this step
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks it works.
AndyAinscow gave the right solution.

Greetings,

Peter Kiers