I have a button click event that stores a number of session variables, like so:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Session(“No_Item”) = Session(“No_Item”) + 1
Label1.Text = Session(“No_Item”)
Session(“Item_Name”) = “Golden Sword”
Label2.Text = Session(“Item_Name”)
Session(“Total_Item”) = Session(“Total_Item”) + 1500
Label3.Text = FormatNumber(Session(“Total_Item”), 2)
Session(“TOTAL_BASKET”) = Session(“Total_Item”)
BASKET.Text = FormatNumber(Session(“TOTAL_BASKET”), 2)
End Sub
THING IS, I want the value of the session variable “Item_Name” to actually be retrieved from a label named “ProductNameLabel” on my page, and I want the value of the session variable “Total_Item” to be the existing value of Total_Item plus a value retrieved from a label named “UnitPriceLabel”. I thought I would be able to do this like so:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Session(“No_Item”) = Session(“No_Item”) + 1
Label1.Text = Session(“No_Item”)
Session(“Item_Name”) = CStr(ProductNameLabel.text)
Label2.Text = Session(“Item_Name”)
Session(“Total_Item”) = Session(“Total_Item”) + CInt(UnitPriceLabel.text)
Label3.Text = FormatNumber(Session(“Total_Item”), 2)
Session(“TOTAL_BASKET”) = Session(“Total_Item”)
BASKET.Text = FormatNumber(Session(“TOTAL_BASKET”), 2)
End Sub
But, as usual, my logic does not apply and the bits in bold are throwing up errors because the labels they refer to are in a DataList and the button click event can’t see them because of this.
Is there a way to make my button click event read the values of labels inside a DataList, and store them as session variables…?
It would also be nice if I could make the session variable name “No_Item” relative to a label - eg it reads a label with the value “1” and makes the session variable name “No_Item_1”, reads a label with the value “2” and makes the session variable name “No_Item_2”, etc., but I think I may be attempting the impossible with that. Actually, for all I know it could be the easiest thing in the world, I really am horribly new at this!
For anyone trying to read the code and figure out what I’m up to - yes, I AM testing out this stuff by pretending to be a shopkeeper from a Zelda game setting up an online store.