470,871 Members | 1,807 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,871 developers. It's quick & easy.

Adding multiple rows through two-way Data binding


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.


May 9 '07 #1
0 1685

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Philip Smith | last post: by
22 posts views Thread by Christopher Murtagh | last post: by
2 posts views Thread by Bob Hollness | last post: by
8 posts views Thread by Najib Abi Fadel | last post: by
9 posts views Thread by howarthc | last post: by
3 posts views Thread by didi86 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.