Adding multiple rows through two-way Data binding

E

EricLondaits

Hi,

I have an ASP.NET page with a ListBox that is data bound to a table
with a single field (it holds a list of valid IDs). The page also has
a textBox into which you can add new valid IDs, one per line (this is
in order to make the process of adding new IDs easy, since it's only
done at time of configuration).

I have no problem with retrieving the contents of the textBox,
splitting it into a string array, validating the individual IDs, and
then creating a dynamic INSERT... but I have a feeling there's a
better ASP.NETish way, and since I'm learning I'm trying to do it in
the most elegant and declarative way.

I thought of two approaches, with which I've been struggling (because
documentation is very sparse for the large topic of data binding):

1 - Add the new IDs into my data bound ListBox and call DataBind() (or
some other method) in the hopes that the two-way data binding will
kick in and add all the new records. I haven't found any documentation
that suggests this will work, however...

2 - Programatically load the parameter into the SQLDataSource and call
the Insert() method so the InsertCommand gets executed.

I feel that number 2 should work... however, I found no way to specify
the parameters or the insert command so that I can insert many new
records with just one command. Is it possible? Is there some better
way than dynamic SQL?

Also, I want to add a button that will allow me to delete the records
selected in the ListBox. Approach number 1 seems more likely here, but
the closest I found to what I need is using a ControlParameter...
however, the ListBox allows multiple selections, so once again I don't
know if it's possible to avoid using a dynamic SQL command (and use
data binding instead) to delete many records at once.

Cheers,
Eric
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top