473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

button click evert error and multiple lablebox text value get

115 100+
Hi Friend

this is my code
Expand|Select|Wrap|Line Numbers
  1.  
  2. protected void Page_Load(object sender, EventArgs e)
  3.     {
  4.         for (int i = 0; i < 10; i++)
  5.         {
  6.             TableRow tr = new TableRow();
  7.  
  8.             TableCell td1 = new TableCell();
  9.             Label lab1 = new Label();
  10.             lab1.ID = "count" + i;
  11.             lab1.Text = i.ToString();
  12.             td1.Controls.Add(lab1);
  13.  
  14.             TableCell td2 = new TableCell();
  15.             Button but1 = new Button();
  16.             but1.Text = "increase";
  17.             but1.Click +=new EventHandler(increasebuttonclick(i));
  18.             td1.Controls.Add(but1);
  19.  
  20.             TableCell td3 = new TableCell();
  21.             Button but2 = new Button();
  22.             but2.Text = "Decrease";
  23.             but2.Click += new EventHandler(decreasebuttonclick(i));
  24.             td3.Controls.Add(but2);
  25.  
  26.             tr.Cells.Add(td1);
  27.             tr.Cells.Add(td2);
  28.             tr.Cells.Add(td3);
  29.  
  30.             Table1.Rows.Add(tr);
  31.  
  32.         }
  33.     }
  34.  
  35.     private object decreasebuttonclick(int i)
  36.     {
  37.         //throw new Exception("The method or operation is not implemented.");
  38.         "count" + i.Text = Convert.ToString("count" + i.Text - 1);
  39.     }
  40.  
  41.     private object increasebuttonclick(int i)
  42.     {
  43.         //throw new Exception("The method or operation is not implemented.");
  44.         "count" + i.Text = Convert.ToString("count" + i.Text + 1);
  45.     }
  46.  
  47.  

here i want

1. button click event with my parameter (ex. increase buttonclick(string i)
2. i want increase my label box value

Pls guide me
Jul 20 '09 #1
1 2091
tlhintoq
3,525 Expert 2GB
Huh? You didn't write the Page_Load portion did you? Anyone who could have written
Expand|Select|Wrap|Line Numbers
  1. Label lab1 = new Label();
  2.  lab1.ID = "count" + i;
  3. lab1.Text = i.ToString();
Would not have written
Expand|Select|Wrap|Line Numbers
  1. private object increasebuttonclick(int i)
  2.     {
  3.         //throw new Exception("The method or operation is not implemented.");
  4.         "count" + i.Text = Convert.ToString("count" + i.Text + 1);
  5.     }
It's good to take someone else's code and tear it apart in an effort to understand how it works. It's a great way to learn more advanced techniques.

Let's take it a piece at a time.

The left side of an equal sign has to be an object, like a variable.
Label Lab1 = for example. Lab1 is a new instance of a Label object.
"count" + i.Text = This is not a variable or object so you can't set it equal to anything.

i.Text + 1 You can't perform math on a string. You might as well be trying to do this "Chair" + 5
also, 'i' is an int. int's don't have a .Text property. Notice when you are typing this in Visual Studio that as soon as you get to the period ( i. ) Visual Studio gives you a drop down menu of things you can pick from. This is a feature called Intellisense. The dropdown is all the properties within i. There are only 6 items in this menu and .Text is not one of them. So you are being told that there is no .Text property to an int.


Declaring all your controls (tables, labels and so on) inside the Page_Load method means you have no way to reference them outside the Page_Load. This is why when you create a form in designer all of that takes place in the Form1.Designer.cs file. The controls are created with form wide scope, if that makes sense. If you make them in Page_Load then the references such as "Lab1" exist only within that method. The controls exist, but its a serious pain to try to reference them for things like.... Lab1.Text = "Bob";

I suggest you start with a simpler project. Just make a form in designer with a label and 2 two buttons: One for add, one for subtract. And work on manipulating the label text from there.

Then, once you have worked that out... try adding a new control programmatically (outside of any method) so it can be seen through-out the form, and try manipulating that.

A little something to get you started
Expand|Select|Wrap|Line Numbers
  1.         int newvalue = i++; //Increase the value of i;
  2.         string status = "Count: " + newvalue.ToString();
Jul 20 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and...
5
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
2
by: techfuzz | last post by:
I scoured this group and others looking for the best way to disable a button after the first click to prevent multiple submissions, but never did find anything that worked like they said it would. ...
2
by: Joey | last post by:
Hi There, I am trying to get the selected value of a listbox when I click a button, everything works ok and I can bind the list and when I have a basic page and click a button to invoke a sub it...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
7
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently...
7
by: =?Utf-8?B?bWFydGluMQ==?= | last post by:
Hi, All, I create button in the code ( Dim Button as new Button), not using button web component (means not drap button and drop it ont he webform), after that I try to use button_click event,...
1
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.