# Storing The Value Of Labels That Are In A DataList As Session Variables?

**URL:** <https://forum.kirupa.com/t/storing-the-value-of-labels-that-are-in-a-datalist-as-session-variables/287162>\
**Category:** programming\
**Created:** [April 27, 2009, 2:01pm UTC](https://forum.kirupa.com/t/storing-the-value-of-labels-that-are-in-a-datalist-as-session-variables/287162 "2009-04-27T14:01:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Spinebuster](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@Joe\_Spinebuster](https://forum.kirupa.com/u/Joe_Spinebuster)\
**Post date:** [April 27, 2009, 2:01pm UTC](https://forum.kirupa.com/t/storing-the-value-of-labels-that-are-in-a-datalist-as-session-variables/287162/1 "2009-04-27T14:01:36Z")

</div>

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. 😑
