Assign value from datagrid to a session variable

J

Jesper Pedersen

This works fine:
<% Session["Session_player"]=1; %>
but this:
<% Session["Session_player"]=%> <%# DataBinder.Eval(Container.DataItem,
"playerID") %> <%; %>

do not work.

The playerID contains the value 1, so the values in both examples are the
same.
What do you suggest - where should i look ??
 
S

Scott Allen

Hi Jesper:

Keep the entire statement inside the data binding delimeters:

<%# Session["Session_player"] =
DataBinder.Eval(Container.DataItem, "playerID") %>

HTH,
 
J

Jesper Pedersen

Hi Scott !

Great...thanks.....now is works......nearly as planned.......

Now, I got to figure out why Session["Session_player"] contains the last
value in the database rather than the current value.

It is assigned in:
<ItemTemplate>
<a href="player_details.aspx?spillerID=<%#
DataBinder.Eval(Container.DataItem, "PlayerID") %>"
target="_parent"> <%# DataBinder.Eval(Container.DataItem,
"playerFirstName") %>
<%#
DataBinder.Eval(Container.DataItem, "playerLastName") %> </a>
<%# Session["Session_player"] =
DataBinder.Eval(Container.DataItem, "playerID") %>
</ItemTemplate>
The <%# Session["Session_player"] = DataBinder.Eval(Container.DataItem,
"playerID") %> display correctly in the Datagrid.

I´am trying to get the player_details.aspx file to receive the current
player.
The spillerID will not be acceptet and now the Session["Session_player"] is
changed to contain the last value in the database insted.

Cmd = new OleDbCommand("SELECT * FROM tblPlayers WHERE PlayerID = " +
Session["Session_player"] + " ", Conn);

R./jp

Scott Allen said:
Hi Jesper:

Keep the entire statement inside the data binding delimeters:

<%# Session["Session_player"] =
DataBinder.Eval(Container.DataItem, "playerID") %>

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

This works fine:
<% Session["Session_player"]=1; %>
but this:
<% Session["Session_player"]=%> <%# DataBinder.Eval(Container.DataItem,
"playerID") %> <%; %>

do not work.

The playerID contains the value 1, so the values in both examples are the
same.
What do you suggest - where should i look ??
 
S

Scott Allen

Hi Jesper -

If the data binding is inside of a Repeater or DataGrid, then it will
execute for each row in the data source. The last assignment will be
from the last row in the data source.

What you might want to do is add some logic so the assignment only
happens on a row that is selected. Look at the ItemDataBound event,
perhaps you could pull it out there. Alternatively, you could add some
additional logic to the data binding expression. See:

Digging Into Data Binding Expressions
http://OdeToCode.com/Articles/278.aspx

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

Hi Scott !

Great...thanks.....now is works......nearly as planned.......

Now, I got to figure out why Session["Session_player"] contains the last
value in the database rather than the current value.

It is assigned in:
<ItemTemplate>
<a href="player_details.aspx?spillerID=<%#
DataBinder.Eval(Container.DataItem, "PlayerID") %>"
target="_parent"> <%# DataBinder.Eval(Container.DataItem,
"playerFirstName") %>
<%#
DataBinder.Eval(Container.DataItem, "playerLastName") %> </a>
<%# Session["Session_player"] =
DataBinder.Eval(Container.DataItem, "playerID") %>
</ItemTemplate>
The <%# Session["Session_player"] = DataBinder.Eval(Container.DataItem,
"playerID") %> display correctly in the Datagrid.

I´am trying to get the player_details.aspx file to receive the current
player.
The spillerID will not be acceptet and now the Session["Session_player"] is
changed to contain the last value in the database insted.

Cmd = new OleDbCommand("SELECT * FROM tblPlayers WHERE PlayerID = " +
Session["Session_player"] + " ", Conn);

R./jp

Scott Allen said:
Hi Jesper:

Keep the entire statement inside the data binding delimeters:

<%# Session["Session_player"] =
DataBinder.Eval(Container.DataItem, "playerID") %>

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

This works fine:
<% Session["Session_player"]=1; %>
but this:
<% Session["Session_player"]=%> <%# DataBinder.Eval(Container.DataItem,
"playerID") %> <%; %>

do not work.

The playerID contains the value 1, so the values in both examples are the
same.
What do you suggest - where should i look ??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top