Assign value from datagrid to a session variable

Discussion in 'ASP .Net' started by Jesper Pedersen, Oct 23, 2004.

  1. 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 ??
     
    Jesper Pedersen, Oct 23, 2004
    #1
    1. Advertising

  2. Jesper Pedersen

    Scott Allen Guest

    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"
    <> 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 ??
    >
     
    Scott Allen, Oct 23, 2004
    #2
    1. Advertising

  3. 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:...
    > 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"
    > <> 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 ??
    >>

    >
     
    Jesper Pedersen, Oct 23, 2004
    #3
  4. Jesper Pedersen

    Scott Allen Guest

    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"
    <> 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:...
    >> 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"
    >> <> 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 ??
    >>>

    >>

    >
     
    Scott Allen, Oct 24, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    501
    Kevin Spencer
    Feb 11, 2005
  2. spiderman

    assign session variable

    spiderman, Aug 6, 2004, in forum: ASP General
    Replies:
    2
    Views:
    127
    Bullschmidt
    Aug 10, 2004
  3. Matt
    Replies:
    2
    Views:
    873
    Anthony Judd
    Sep 25, 2004
  4. Mirovk
    Replies:
    2
    Views:
    171
    Mirovk
    Aug 22, 2006
  5. Replies:
    4
    Views:
    1,940
    Anthony Jones
    Oct 9, 2006
Loading...

Share This Page