简体   繁体   English

如何随机访问中继器的项目

[英]How To Access Repeater's Items Randomly

I have a repeater with an ItemTemplate contains a CheckBox , TextBox 我有一个带有ItemTemplate的转发器,其中包含一个CheckBoxTextBox

My repeater represents a check list plus a TextBox to put a comment to each item I select from the list. 我的中继器代表一个检查列表以及一个TextBox用于对我从列表中选择的每个项目添加注释。

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. PageView首先,在“转发器”中填充了“项目”表中所有的项目,并且没有复选框或其他任何内容。

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. 然后,我选择一个特定的购物车(例如cartId = 1)进行编辑,这是我对操作的真正困惑:现在,转发器将有15到20个项目,因此我只需要访问用户所需要的项目在用户要编辑的当前购物车(cartId = 1)上进行选择,这样他就可以知道自己选择了什么,然后开始选择新值,选中/取消选中CheckBoxes等。


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. 这样,您可以对两个转发器使用简单的SqlDataSource控件,并根据第一个转发器中的当前订单选择,将ControlParameter添加到用于检索订单项的数据源中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM