473,387 Members | 1,882 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,387 software developers and data experts.

Storing values into EventArgs

I am currently building a shopping cart application in C# where there are 10 items to select from. There are 10 "Add to Cart" buttons, when clicked, will trigger a single method. That single method will either add a row (new item), or update the quantity (old item). In my existing code, i loop through each row in the DataSet to determine whether i should add a row or update a row.

Is there a way to store the item information (name, description and price) in EventArgs so that when the "Add to Cart"
button is clicked, the item information is passed to the single method using EventArgs?
Feb 9 '07 #1
3 4971
I am currently building a shopping cart application in C# where there are 10 items to select from. There are 10 "Add to Cart" buttons, when clicked, will trigger a single method. That single method will either add a row (new item), or update the quantity (old item). In my existing code, i loop through each row in the DataSet to determine whether i should add a row or update a row.

Is there a way to store the item information (name, description and price) in EventArgs so that when the "Add to Cart"
button is clicked, the item information is passed to the single method using EventArgs?
Hi,

You can create a custom EventArgs class, by making your class a subclass of the EventArgs class. This will allow you to add any data you want as instance members.

E.g.

public class MyCustomEventArgs : EventArgs
{

private int myInteger;
private string myString;

public MyCustomEventArgs(int myInteger, string myString)
{
this.myInteger = myInteger;
this.myString = myString;
}

//and some properties to access these data indivually (if required)
public int MyInteger
{
get { return myInteger; }
set { this.myInteger = value; }
}

//...
//...
}

Hope it helps.

Cheers
Feb 9 '07 #2
I tried to create my own EventArgs class called ItemEventArgs, and just pass it into the AddToCartMethod.

<asp:Button ID="Button1" runat="server" Font-Size="Small" Text="Add to Cart" OnClick="AddToCart" /></p>

The above button in an aspx page will trigger the method below

protected void AddToCart(object sender, ItemEventArgs e)
{
//...
}

But i get an error saying that "No overload for "AddToCart" matches delegate 'System.EventHandler"
Feb 9 '07 #3
I tried to create my own EventArgs class called ItemEventArgs, and just pass it into the AddToCartMethod.

<asp:Button ID="Button1" runat="server" Font-Size="Small" Text="Add to Cart" OnClick="AddToCart" /></p>

The above button in an aspx page will trigger the method below

protected void AddToCart(object sender, ItemEventArgs e)
{
//...
}

But i get an error saying that "No overload for "AddToCart" matches delegate 'System.EventHandler"
Hi,

All this should be implemented with the use of delegates. Here are the steps:

1. first define you delegate (probably outside the class declaration) e.g.
public delegate void AddToCartEventHandler(object sender, ItemEventArgs e);

2. Create your event in ur class e.g.
public event AddToCartEventHandler addToCartEventHandler;

3. register you AddToCart method to the event e.g.
yourInstanceObject.addToCartEventHandler += new AddToCartEventHandler(AddToCart);

4. Whenver you button is pressed by the user, raised the event addToCart..e.g.
addToCartEventHandler(this, e);

where e an instance of the event args you created before (i think it's ItemEventArgs)...

Hope it helps.

Cheers!
Feb 12 '07 #4

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

Similar topics

6
by: gv | last post by:
Hi all, I need to store values in a client application then later when done send them to SQL 2000. I know there is several ways to do this but, looking for the fastest , and most effient way...
3
by: trickish | last post by:
In my main I try to get values assigned to "int *thisSoduko" through the static method Reader::read. int main(char *args) { ... int *thisSoduko = new int; if(Reader::read( fileName,...
5
by: kadidarm | last post by:
Hi I have just started to make a Bill of Material Program (BOM) for my self using Microsoft Access 2003. I am looking to make a recipe database. The problem I am having is this: I have a table...
0
by: velu | last post by:
Problem in storing values from Executescaler() (inside a data grid.) Situation: I have placed a panel inside a datagrid, which populate a table from a database. Now, I run a query to compare...
3
by: ag203 | last post by:
I need to store 25 different values (1, 5, 10, 25 etc. theres no pattern) in an array and then when the user picks a number q through 25 one of those values (randomly not the same one every time)...
10
by: drago | last post by:
Hello guys again! Back with invoice problems. Just want to know how to store data in the main database in different tables and fields using a form. I have a datasheet view of a form where i have to...
2
by: teambau | last post by:
I'm encountering an error in MS Access 2007 when I try to store values from a form to a table. Here's a snippet of the VB: Private Sub Submit_Update_Click() Dim DB As Database Dim new_comment As...
3
by: jdfergus | last post by:
Hello, I have a field "MappedTo" in a subform "OldCodes" thats needs to refer to a field "NCodes" in the main form "NewCodes" based on whether a field in the subform "Decision" is checked or not. I...
0
by: Sourav sarkar | last post by:
I already use combo Box Column for the above reason but I want to press enter to move to next column, don't want to use tab key to move to next cell. and tab key to move to next column. Please...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.