Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Adding event handler for dynamically created controls

Reply
Thread Tools

Adding event handler for dynamically created controls

 
 
=?Utf-8?B?QW5kcmV3IFdpZWQ=?=
Guest
Posts: n/a
 
      04-19-2004
Hello
Please excuse me if this come in as a duplicate.

Here is the situation that I am having: I am pulling data from a database and writing it out as a list. Next to each item that I write, I want to make a linkbutton control which will allow you to invalidate the database record. Since I don't know how many records will be present, I need to have all of the linkbuttons access the same event. The trick is to know WHICH linkbutton was pressed. Is there a way that anyone can suggest to accomplish this? I have been trying to do this for a good deal of time so far
Thank you
Andre

 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmlsbCBCb3Jn?=
Guest
Posts: n/a
 
      04-19-2004
Andrew, I presume you are writing it out as a datalist. No matter which button the user clicks in the datalist, the ItemCommand event fires. Inside ItemCommand, e.item is the datalistitem of the row that was clicked, and in e.item.controls you'll find the data that's shown in the grid. In addition to or instead of, you can bind the linkbutton's CommandArgument property to your primary key field, then retrieve CommandArgument in ItemCommand and use it to go get your data from somewhere, etc. (this is handy when you want a key or something that you're not showing in the grid, although you can do that too with hidden fields). ht

Bil

----- Andrew Wied wrote: ----

Hello
Please excuse me if this come in as a duplicate.

Here is the situation that I am having: I am pulling data from a database and writing it out as a list. Next to each item that I write, I want to make a linkbutton control which will allow you to invalidate the database record. Since I don't know how many records will be present, I need to have all of the linkbuttons access the same event. The trick is to know WHICH linkbutton was pressed. Is there a way that anyone can suggest to accomplish this? I have been trying to do this for a good deal of time so far
Thank you
Andre

 
Reply With Quote
 
 
 
 
=?Utf-8?B?QW5kcmV3IFdpZWQ=?=
Guest
Posts: n/a
 
      04-20-2004
Thank you for the reply
Actually, I'm not using a datalist. Basically, I am wondering if there is a way to get two or more (a variable quantity) of controls[linkbuttons, specifically] to fire the same event, and have the event handler know which one threw the event

Is there a way that anyone knows

Thanks
Andre

----- Bill Borg wrote: ----

Andrew, I presume you are writing it out as a datalist. No matter which button the user clicks in the datalist, the ItemCommand event fires. Inside ItemCommand, e.item is the datalistitem of the row that was clicked, and in e.item.controls you'll find the data that's shown in the grid. In addition to or instead of, you can bind the linkbutton's CommandArgument property to your primary key field, then retrieve CommandArgument in ItemCommand and use it to go get your data from somewhere, etc. (this is handy when you want a key or something that you're not showing in the grid, although you can do that too with hidden fields). ht

Bil

 
Reply With Quote
 
=?Utf-8?B?QmlsbCBCb3Jn?=
Guest
Posts: n/a
 
      04-25-2004
Just attach the same handler to the event you want from each of the controls, then in the handler use the "sender" object to figure out who sent it--e.g. you've got a bunch of buttons, you attach MyButtonHandler to each button's Click event, and then in MyButtonHandler you do something like (button)sender.name to figure out who was clicked. Does that help

----- Andrew Wied wrote: ----

Thank you for the reply
Actually, I'm not using a datalist. Basically, I am wondering if there is a way to get two or more (a variable quantity) of controls[linkbuttons, specifically] to fire the same event, and have the event handler know which one threw the event

Is there a way that anyone knows

Thanks
Andre

----- Bill Borg wrote: ----

Andrew, I presume you are writing it out as a datalist. No matter which button the user clicks in the datalist, the ItemCommand event fires. Inside ItemCommand, e.item is the datalistitem of the row that was clicked, and in e.item.controls you'll find the data that's shown in the grid. In addition to or instead of, you can bind the linkbutton's CommandArgument property to your primary key field, then retrieve CommandArgument in ItemCommand and use it to go get your data from somewhere, etc. (this is handy when you want a key or something that you're not showing in the grid, although you can do that too with hidden fields). ht

Bil

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Affecting a dynamically created drop down from another dynamically created drop down. msimmons ASP .Net 0 07-16-2009 03:17 PM
How to refer to a dynamically created control in event handler? gnewsgroup ASP .Net 4 02-19-2008 09:38 PM
Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created) dickster ASP .Net Building Controls 0 12-08-2005 09:32 AM
Adding Event Handler to Dynamically added Controls John Kilgo ASP .Net Web Controls 4 04-26-2005 02:05 PM
Passing event from dynamically created element and event handler? Adi Javascript 2 02-23-2004 02:44 PM



Advertisments