First off, excuse my ignorance of both ASP.NET and CSLA.NET 3.x. I am a religious user of CSLA.NET 2.x with WinForms and am working on upgrading and learning ASP.NET at the same time.
I want to provide the users a list of records (events for sake of discussion) in a grid view. I have two thoughts on approaches but just need one solution for now. I want to allow the user to select an event from the list to have it copied.
One approach would be to provide a "Copy" command next to each record. Frist, I'm not sure how to create that in the grid. Second, I'm not sure how to fire an event for the code-behind to process. I noticed the EventsDataSource_SelectObject event that is used to populate the gridview. That seems to work fine. And, I know there are insert, update and delete buttons/commands and events in the datagrid view that tie to CSLADataSource events. But, how do I do a different command? I suppose I could "use" one of the other commands and change the display text but that just doesn't feel right. Am I missing a fairly simple solution here?
Another approach would be to have one "Copy" button on the page at the top or bottom (multi-selecting would also be nice). Then, the button can process the selected event. However, I see no easy way of selecting an event without having the user first click a "select" command (with a postback) then click the Copy button. Further, is the business object available from the databinding at this point?
If either or both of these answers are trivial and just require a little training/research on my part of a certain area, just give me some keywords to point me in the right direction. Regardless, I'm taking any and all responses.
Please help!
I have been using CSLA with ASP.Net for about 5 years now. I have been happy using a standard DataGrid for a long time. I do not use the newer Gridview or the CSLA DataSource.
You are asking for a couple of different things here. Select one or multi-select.
Mutli-select is another topic.
For "select one" I like to add a column labeled Action at the end of the grid with one or more buttons in it (depending on how many actions you want to take for the current row.)
The .aspx page with the datagrid has this as the last column:
<
asp:TemplateColumn HeaderText="Action">The .aspx page datagrid declaration has this (plus a lot more) in it:
id="dgResults" runat="server" OnItemCommand="GetRowInfo"
The code behind page has this code in it to trap the selected row and store the key value in Session and call the next page:
Protected
Sub GetRowInfo(ByVal source As Object, ByVal e As DataGridCommandEventArgs)The main idea is that on postback of the page (by clicking btnAmend in the row) you pull the Read Only Collection (ROC) from Session and then use the index of the row to find the item in the collection. Since I use LINQ for sorting I re-bind the ROC to a variable named mSortedList - this way the index of the item in the page lines up with the sorted index of the collection and you easily find the item. (Note e.Item.Index is different from e.Item.DatasetIndex! The first is only good for 1 page - it starts over at 0 on each subsequent page. The datasetindex continues incrementing and matches the index of your collection.)
HTH
Joe
Thanks for the quick response. However, I'd prefer to stick with the GridView.
Some of your comments are very helpful though. I need to look at the TemplateColumn further.
I'm used to WinForms data binding where the "code behind" has access to the business object (via Row.DataBoundItem). Then, I can peform all my actions against the business object rather than the actual controls.
With that said, I'm wondering how to use the CSLADataSource for something other than Select, Insert, Update or Delete. I actually got it to work properly by using the Delete functionality (since it provides access to the data key) but renamed it to say "Copy". I don't feel like this is best practice but I don't know of any other way of doing it.
I suppose I could extend the control as well but I would have thought this extended functionality would be feasible already.
Additional input please?
Copyright (c) Marimer LLC