Attaching Event With Parameters to image control created dynamicll

G

Guest

Hello,

Here's the situation (I'll try to be brief as possible)
I am working on the control which is created dynamically based on XML
string. This control consists of a table with number of rows with 3 columns;
TextBox, dropdown and a button ("Delete" button) in each column. Also there's
one button at the bottom of the table that allows users to add more rows. So
more controls will be added programmatically as user adds more rows.
What's the easiest way to associate an event with each Delete button which
will take rowID as a parameter. So when a particular button is clicked
appropriate row will be removed.

Thank you guys for any feedback...
 
K

Karl Seguin

Why not use a repeater and simply use the ItemCommand event of the repeater?

The delete button's event will bubble up to the ItemCommand event, which you
can catch, and figure out which row was clicked via a number of ways
(commandARgument, using a hidden field)...

You can check out more about this at:
http://openmymind.net/databinding/index.html#8 (might wanna read the whole
thing though).

Karl
 
G

Guest

Thank you for your response.

I guess data Repeater could work, but .....
This control is a little more complicated than simply displaying rows of
data and deleting one row at a time:
1. It's source is a custom XML string (I guess I has to be converted to
dataset to be databound.)
2. Dropdown is driven by data that varies by RowID
3. After user adds new row or removes existing rows each row must be
validated.

I am not sure if Repeater can satisfy these requirements. I'd rather develop
my own logic that parses XML and creates each control programmatically. I
will look into repeater if nothing else works. Thanks.
Any other sugestions?
 
K

Karl Seguin

Well, each delete button can be hooked into the same event, and you can
simply set the RowId to the commandArgument so you'll know which row to
delete.

Karl
 
G

Guest

Ok, How can I add a dropdwon control populated by another data source to
ItemTemplate and select one of the dropdown's item based on the value from
database.
All this information is contained within XML. That's why I am look for
custom programming solution, but if Reapeter can handle above requirement,
I'll go with that.
 
K

Karl Seguin

If you are using a Repeater, you can hook into the ItemDataBound event and
easily do that in codebehind (the tutorial I pointed you to has details on
that), something like:

sub ItemDataBound(...)
dim ddl as DropDownList = ctype(e.Item.FindControl("dropdown"),
DropDownList)
ddl.DataSource = yourOtherDataSource;
ddl.DataBind()
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue("TheValue"))
end sub

Karl
 
G

Guest

I just glimpsed over your tutorial... I think it's exactly what I was looking
for!! and it's a great tutorial, very concise and to the point. Thanks.
I can put together dataReapeter with nested databinding, no problems. Now I
need to figure out how to retrieve all the data entered into the repeater's
controls. I think I have some ideas on how do to that, pobably looping
through ItemTemplates and .FindControls for what I need, right? I have a
feeling I'll be posting again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top