Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Assign value from datagrid to a session variable

Reply
Thread Tools

Assign value from datagrid to a session variable

 
 
Jesper Pedersen
Guest
Posts: n/a
 
      10-23-2004
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 ??


 
Reply With Quote
 
 
 
 
Scott Allen
Guest
Posts: n/a
 
      10-23-2004
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/

On Sat, 23 Oct 2004 21:14:01 +0200, "Jesper Pedersen"
<(E-Mail Removed)> wrote:

>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 ??
>


 
Reply With Quote
 
 
 
 
Jesper Pedersen
Guest
Posts: n/a
 
      10-23-2004
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" <bitmask@[nospam].fred.net> skrev i en meddelelse
news:(E-Mail Removed)...
> 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/
>
> On Sat, 23 Oct 2004 21:14:01 +0200, "Jesper Pedersen"
> <(E-Mail Removed)> wrote:
>
>>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 ??
>>

>



 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      10-24-2004
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/

On Sun, 24 Oct 2004 00:37:23 +0200, "Jesper Pedersen"
<(E-Mail Removed)> wrote:

>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" <bitmask@[nospam].fred.net> skrev i en meddelelse
>news:(E-Mail Removed).. .
>> 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/
>>
>> On Sat, 23 Oct 2004 21:14:01 +0200, "Jesper Pedersen"
>> <(E-Mail Removed)> wrote:
>>
>>>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 ??
>>>

>>

>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assign Javascript value to asp session variable philin007@gmail.com ASP General 4 10-09-2006 10:00 AM
Assign a value to a Session variable from an Script Mirovk ASP General 2 08-22-2006 02:04 PM
Preferred Method To Assign Session Variable Values Matt ASP .Net 1 02-11-2005 09:07 PM
assign javascript variable value to VBScript server side variable Matt ASP General 2 09-25-2004 10:40 AM
assign session variable spiderman ASP General 2 08-10-2004 02:22 AM



Advertisments