In simple terms, I have an ASP repeater which is meant to display a list of items for a wedding list, including the name of the item, how many are available and a button to take the user to a "purchase" form where they select how many they wish to purchase. Once they're done, the page is reloaded and the new "number available" is displayed. Sounds simple, huh?
Well it damn well should be, but unfortunately, my partner and I have been working on this for 3 days and we cannot work out a way to get the item ID in the following line:
Expand|Select|Wrap|Line Numbers
- <input type="button" onclick="window.open('AnotherPage.aspx?ID=<%#DataBinder.Eval(Container.DataItem, "ItemID")%>');" ... />
- The #DataBinder code includes a double-quoted "ItemID". It doesn't seem to matter which way we try and arrange the quotes on the onclick command, we cannot get it to work (e.g. single quotes on the onclick, double quotes in the window.open, vice-versa, no quotes on the on-click etc.) with errors generally coming down to improperly formatted html etc.
- The repeater severely limits the use of getElementById and other useful javascript methods because, obviously, any elements within the repeater will be repeated
We have managed to get around this before by using the single quotes on the attribute value, but that only works when there's no javascript, e.g.:
Expand|Select|Wrap|Line Numbers
- ... class='<%#DataBinder.Eval(Container.DataItem, "ClassName")%>'...
Expand|Select|Wrap|Line Numbers
- <input itemnumber='<%#DataBinder.Eval(Container.DataItem, "ClassName")%>' onclick="window.open('AnotherPage.aspx?ID=' + this.itemnumber);" />
We thought perhaps using a legitimate attribute would work, so we tried using the "id" attribute, but aparently element ids cannot be produced dynamically.
Does anyone know either a way to fix this so it works or a better way of doing what I'm trying to achieve? We basically need some way to send the ID of the current item to the "purchase" form when the user clicks the button.
We have tried doing the same things using an <asp:button /> as well, but run into similar problems with that.
Eagerly awaiting a response.
~ Q