Sunday, February 19, 2012

Help with UPDATE with SqlDataSource and a Repeater

Hi,

I have a repeater which i need to build editing capabilities into in a similar way as the GridView, just a little unsure how to tie it together. Ideally i would like to use a GridView as this would do all of the work for me however it looks like I need to go with the repeater due to the nested nature of the data I am working with.

What is the best way to go about updating the data source from within a repeater? I have already built the edit interface with some MultiViews in the Repeater control and handling the ItemCommand event, just not sure how to actually update the data source.

Can I still use the SqlDataSource wizard to generate all of the SQL for me? If so, within the ItemCommand event handler I have the data i want to update back to the database by using the FindControl method and retrieving the Text, but how do i get this data into the SqlDataSource object and update the database?

Are there any samples available which show how to update a datasource using a repeater?

Your help is much appreciated

trenyboy

Have you thought about using a DataList, this is halfway between the GridView and the Repeater, but it's certainly easier to work with :-)

Have a look at thissample for an example of DataList binding, and thisone for an example of updating.

|||

No, I hadn't up until now! I was using the repeater because I have nested data which I needed to appear as if it were part of the same table, hence I need to render the html myself, but I see the DataList will also allow for this!

Does the DataList have support for Edit/Update in a similar way as the GridView does with using the SqlDataSource wizard and no custom code (ASP.NET 2.0)? If not, what would be the advantage for using the DataList over the Repeater?

Thanks

|||I'm not sure what you mean by "nested data". If you could explain that a little better I'm sure someone could come up with a good solution for you. Is the nested data from the SQL Server, and you want to add some more columns on to it, or is the nested data something being generated by the ASP.NET application like in an array/list?|||By nested data I am referring to parent/child relationships. Ihave summary (parent) rows which contain one or more detail (child)rows. All rows need to look as though they are part of the sametable, however, the parent rows provide an option to show or hide allof its related child rows.

What I have done to get around this is to use one repeater for theparent data, and another repeater for the child data, this way I ammanually rendering the html as a single table, but I can show/hide thischild repeater via its visible property.

It is from SQL Server, and all i want to be able to do is provide anediting functionality to allow the user to update the underlyingdatasource from the interface.

Does this make more sense?|||

Yes it does. I've never done that myself, but perhaps someone else here has.

If it were me, I would use a query to return all the data I wanted in the order I wanted, then use the gridview, and write my own javascript to hide/show the child rows.

|||

trenyboy wrote:

Does the DataList have support for Edit/Update in a similar way as the GridView does with using the SqlDataSource wizard and no custom code (ASP.NET 2.0)? If not, what would be the advantage for using the DataList over the Repeater?

No it doesn't. What I've always done in the past is implement my DataList_UpdateCommand and simply call the update on the DataAdapter that is Filling the DataSet that backs up the DataList. Then you can use QueryBuilder to generate the Update for you.

In fact I'm starting to think I might be able to use an ObjectDataSource here, I may have to experiment a little :-)

No comments:

Post a Comment