I have a repeater with an ItemTemplate contains a CheckBox, TextBox
My repeater represents a check list plus a TextBox to put a comment to each item I select from the list.
Now, I've a page for editing an existing shopping cart in my database and it uses this repeater to enable the user to update his list. So I need to update the List with the previous selected values from the database. I can't think of a simple logic or way to access only the repeater's items that are on the previous list ...I'm thinking about trying to access each item that's in my database only instead of looping and looping.
I know It's really confusing so I'll just put it in a more illustrative way:
Database View
Items
=======================
ID Name
--- -----
1 Banana
2 Apple
3 Strawberry
4 Orange
ShopCart_Items
========================================
ItemID ItemName CartID Value
------- --------- ------- ------
2 Apple 1 1
4 Orange 1 2
2 Apple 2 2
PageView
First the repeater is populated with all the items that I have in my 'Items' table and no boxes check or anything.
Then I choose a specific cart (say cartId = 1) to edit, and here's what I'm really confused on how to do:
Now the repeater will have like 15-20 items, so I need to access just the items that the user choose on the current cart (cartId = 1) that the user want to edit, so he could know what did he choose and start choose new values, check/uncheck CheckBoxes, etc.
I'm sorry for all this long question, but I'm really confused should/can I access each item directly or what logic do you advice me to use ? ..Thanks =)
I believe that you have mix two different entities in a one repeater - an orders and order items.
In my opinion the better approach is to place two repeaters onto the page: the first one for displaying orders and the second one for displaying order items for the selected order. This way you may use simple SqlDataSource controls for both repeaters and add a ControlParameter to the datasource used for retrieving order items depending on current order selection in the first repeater.
Related
I am populating a ListView with a DataTable from the code behind. The problem is, that the ListView is becoming too long with too many items.
I am wondering, how can I make this:
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Into this:
Item 1 Item 4
Item 2 Item 5
Item 3 Item 6
Maybe I'm overlooking something, but I can't seem to find the answer.
Please not that I want to keep it in one ListView, so I'm not looking to split the items and put them into multiple ListViews.
Solution: Use a DataList in stead of a ListView. See Tim's answer.
Use a DataList instead. It has a RepeatDirection and RepeatColumns properties. The former would be RepeatDirection.Vertical and the latter 2 in your case.
Gets or sets the number of columns to display in the DataList control.
For one of my projects I need to allow the user to select some products out of a table.
This table will be paged (+2k records in DB).
So the user needs to be able to select items on different pages without losing them.
I was thinking about using 2 tables. One table to select items from and another table(also with paging) where the selected items will be displayed.
But I have no idea how to persist the selected items without using Sessions...
If anybody has a better idea please share it.
Edit:
It is possible(won't happen that much) to select all products (+2k records).
I don't know how mvc will behave if you have 2k hidden fields.
Also lets say i use hidden fields and have the following in my viewmodel
public List<int> SelectedIds {get;set;}
I can then use hidden fields with "SelectedIds[i]" as name(replacing i by an integer).
But the user can also deselect the items again.
And I don't think the binding will work when you skip numbers.
ex: 2 hidden field with these names "SelectedIds[0]" && "SelectedIds[2]"
This is something I'll have to test when i am home...
I am developing a small business application to display the report retrieved from database and I have a checkboxlist consisting of four checkboxes, also a combobox. Now, I am retrieving the required info from database to combobox with 4 items while on page load, which is ok. Not only this, but also retrieving the checkboxlist DataTextField on the checkboxes from database,which is also ok.
As for my question on this issue, lets assume that I have a combobox with 2 items, name and age and also 4 checkboxes named with George, Michael, 23, 33.
Here, 23 and 33 belong to Name(combobox.selectedindex[0]) items of checkboxes and George, Michael belong to the Age item of combobox. Then, I want to display on the listbox that when clicking Name item of combobox, checkboxes of Michael and George come to the screen as checked automatically and when clicking the button, those selected values of checkboxes are displayed on the listbox for both nMme and Age items of combobox in the same logic.
I tried to make this several times, but fail to achieve this goal. How to do this, can you please lead the way to me on my this issue?
Thank a a lot for replying.
The simple way would be to add Name or Age as checkBoxListItem.Tag to the corresponding values and everytime you change selection in the combobox you iterate through all the checkBoxItems and chack the ones with the corresponding tag and uncheck the others.
I have a simple dropdown list, currently using asp:ListItem to populate tho this will be changed to a db at some later point.
Depending on the users choice, I then want to present them with between 2 and 5 Lables and Textboxes so that they can enter values then run an algorythm.
The Lables and Textboxes, let call em items, will always have 1 and 2 shown, however 3-5 can be present in any combination but preferably always in order so 5 never comes before 3 and 4 etc.
I also dont want there to be any gaps if say 3 and 4 are missing, so making them invisible isnt an option either.
Is there some form of table or listbox option than can allow me to simply do the above ? Or do I have to change the text etc for each "line" as required ?
I basically want the following (example with Lines/items 3 and 4 not required) -
Item1 VALUE ______
Item2 VALUE ______
Item5 VALUE ______
Many thanks, George.
The best thing is that according to user choice make Item3 as Item5 and hide all other controls
:)
Use jQuery or basic Javascript to set the display property as none for the items that you don't want to be displayed. This way there wouldn't be any gaps on the UI for the hidden items.
I'm designing an ASP.NET screen which configures what screens are relevant for a particular type of record. For example a car record will have access to the Ford and Ferrari pages. I'm displaying a listbox on the left with all available items, and a listbox on the right with currently selected items. Two arrow icons allow you to move items from left listbox to right listbox and vice versa.
I'm trying to figure out a good way of storing the selected access. Easiest would be to delete all the currently selected items and reinsert the items from the Selected Items listbox. But the changes need to be audited more accurately so need individual inserts and deletes. Should I store the original items in a hidden field and then try to compare the final selected items with the original? Should the work be done in the Presentation layer, within an object or in a stored procedure?
Thanks for any guidance,
Dean
I would not do it on the presentation layer, send the new list to your business layer. In there retrieve the current list and do a compare with the new list. The do your inserts and deletes based on that.
If you want the selection to be persistant you should store them in DataLayer.
Business Layer : Car Entity and Cars Collection
At server side you can create a collection of items that contains all (selected/ not selected) items.
A car entity item requires its name, id and selected info. store this collection in session when user enter the page and check it whenever you want.
Here is a Car Item :
CarItem
Id
Name
IsSelected