retrieve session id from login page and update datasource through gridview

Hello,
I have a gridview that is connected to an sqldatasource and I would like to add in the updatecommand the session id (retrieved from the login.aspx.cs) so that I can store it back in the datasource when a user updates a row in the gridvew.
I'm using DataReader.
Thanks a million.
wilson082572Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vavjeevaCommented:
please explain your question in detail. post your source code for more understanding.
0
wilson082572Author Commented:
I have a field in the database called user-id.  In this field I want to store the user-id of the person who updated the data in the gridview.
the code in the Login.aspx.cs is:
protected void btnLogin_Click(object sender, EventArgs e)
    {
        IDataReader dr = data_access.Login_Check(txtUserName.Text, txtPassword.Text);
        DataTable dt = new DataTable();
        dt.Load(dr, LoadOption.OverwriteChanges);
        DataTableReader dtr = dt.CreateDataReader();
       
        if (dtr.HasRows)
        {
            dtr.Read();
            Session["authenticated"] = true;
            Session["login_user_id"] = Convert.ToInt32(dtr["user_ID"]);
            Session["user_level_id"] = Convert.ToInt32(dtr["user_lvlID"]);
            Session["user_fullname"] = dtr["user_fullname"].ToString();
...
and in the aspx with the gridview:

I know that this is wrong:
trspfb_UserID = <%# Session["login_user_id"] %>
in the UpdateCommand but I'm not sure what syntax I'm supposed to use

Thanks again.
<%@ Page Language="C#" MasterPageFile="~/templates/DefaultMaster.master" AutoEventWireup="true" CodeFile="Feedback_List2.aspx.cs" Inherits="sslogin_Feedback_List" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphTitle" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphMain" Runat="Server">
    <asp:GridView ID="GridView1" runat="server" Width="100%" 
    AllowSorting = "True"
    AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AllowPaging="True" PageSize="15" DataKeyNames="trspfb_ID" CellPadding="2" >
        <Columns>
            <asp:CommandField ShowSelectButton="True" >
            </asp:CommandField>
            <asp:CommandField ShowEditButton="True" />
            <asp:CommandField DeleteText="Disable" ShowDeleteButton="True" />
            <asp:TemplateField HeaderText="Email Alert">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("trspfb_emailalert") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <a href="mailto:<%# Eval("trspfb_emailalert") %>"><%# Eval("trspfb_emailalert")%></a> 
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="trspfb_LastName" HeaderText="LastName" SortExpression="trspfb_LastName" />
            <asp:BoundField DataField="trspfb_FirstName" HeaderText="FirstName" SortExpression="trspfb_FirstName" />
            <asp:BoundField DataField= "trspfb_Card4DigitsFirst4" HeaderText="CC# First5" SortExpression="trspfb_Card4DigitsFirst4"/>
            <asp:BoundField DataField="trspfb_Card4Digits" HeaderText="CC# Last5" SortExpression="trspfb_Card4Digits" >
                <ItemStyle HorizontalAlign="Center" Width="50px" />
            </asp:BoundField>
            <asp:BoundField DataField="trspfb_Contract" HeaderText="Contract" SortExpression="trspfb_Contract" />
            <asp:BoundField DataField="trspfb_email" HeaderText="Email" SortExpression="trspfb_email" />
            <asp:BoundField DataField="trspfb_phone" HeaderText="Phone" SortExpression="trspfb_phone" />
            <asp:BoundField DataField="trspfb_company" HeaderText="Company" SortExpression="trspfb_company" />
            <asp:TemplateField HeaderText="Feedback" SortExpression="trspfb_feedback">
                <EditItemTemplate>
                 <asp:TextBox ID="TextBox1" runat="server" ReadOnly="True" Text='<%# Bind("trspfb_feedback") %>' Enabled="False" Columns="20"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("trspfb_feedback") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" Width="150px" Wrap="False" />
                <HeaderStyle HorizontalAlign="Center" Width="150px" Wrap="False" />
            </asp:TemplateField>
            <asp:BoundField DataField="trspfb_DateCreated" HeaderText="DateCreated" SortExpression="trspfb_DateCreated" >
                <ItemStyle HorizontalAlign="Center" Wrap="True" Width="10px" Height="2px" />
            </asp:BoundField>
            <asp:BoundField DataField="trspfb_ID" HeaderText="trspfb_ID"
                ReadOnly="True" SortExpression="trspfb_ID" Visible="False" />
            <asp:BoundField HeaderText="Notes" DataField="trspfb_Notes" SortExpression="trspfb_Notes" />
            <asp:CommandField ShowDeleteButton="True" />
            <asp:CommandField ShowEditButton="True" />
            <asp:CommandField ShowSelectButton="True" />
   
        </Columns>
        <PagerSettings FirstPageText="First" LastPageText="Last" NextPageText="Next" PreviousPageText="Previous" Mode="NextPreviousFirstLast" />
        <RowStyle CssClass="Table_Row" />
        <HeaderStyle CssClass="Table_Title" ForeColor="White" />
        <AlternatingRowStyle CssClass="Table_AltRow" />
        <SelectedRowStyle CssClass="Table_RowSelect" />
        
        
   </asp:GridView>
    &nbsp;&nbsp;
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnHTA %>"
        SelectCommand='select   [trspfb_LastName], [trspfb_FirstName], [trspfb_Card4DigitsFirst4], [trspfb_Card4Digits], [trspfb_Contract], [trspfb_email], [trspfb_phone],[trspfb_company], [trspfb_feedback], trspfb_emailalert,trspfb_DateCreated,trspfb_ID,trspfb_Notes from Trsp_FeedBack where trspfb_Active > 0 and ((len(trspfb_feedback) > 0 or len(trspfb_emailalert) > 0)) order by trspfb_DateCreated asc' DeleteCommand="update Trsp_FeedBack set trspfb_Active = 0 where trspfb_ID = @trspfb_ID" UpdateCommand='update Trsp_FeedBack set trspfb_LastName=@trspfb_LastName, trspfb_FirstName = @trspfb_FirstName, trspfb_Card4DigitsFirst4 = @trspfb_Card4DigitsFirst4, trspfb_Card4Digits = @trspfb_Card4Digits, trspfb_Contract = @trspfb_Contract, trspfb_email = @trspfb_email,  trspfb_phone = @trspfb_phone, trspfb_company = @trspfb_company, trspfb_feedback = @trspfb_feedback, trspfb_emailalert = @trspfb_emailalert, trspfb_DateCreated = @trspfb_DateCreated, trspfb_Notes = @trspfb_Notes, trspfb_UserID = <%# Session["login_user_id"] %>
 where trspfb_ID = @trspfb_ID'>
         <SelectParameters>            
            <asp:SessionParameter Name="trspfb_UserID" SessionField="login_user_id" Type="int32"/>
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="trspfb_ID" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="trspfb_LastName" />
            <asp:Parameter Name="trspfb_FirstName" />
            <asp:Parameter Name="trspfb_Card4DigitsFirst4" />
            <asp:Parameter Name="trspfb_Card4Digits" />
            <asp:Parameter Name="trspfb_Contract" />
            <asp:Parameter Name="trspfb_email" />
            <asp:Parameter Name="trspfb_phone" />
            <asp:Parameter Name="trspfb_company" />
            <asp:Parameter Name="trspfb_feedback" />
            <asp:Parameter Name="trspfb_emailalert" />
            <asp:Parameter Name="trspfb_DateCreated" />
            <asp:Parameter Name="trspfb_Notes" />
            <asp:Parameter Name="trspfb_ID" />
                        <asp:SessionParameter Name="trspfb_UserID" SessionField="login_user_id" Type="int32"/>
 
        </UpdateParameters>
 
        
     </asp:SqlDataSource>
     
</asp:Content>

Open in new window

0
vavjeevaCommented:
yeah.. add sessionparameter and use that ..

<asp:SessionParameter Name="SessionUserID" SessionField="login_user_id" Type="String" />

and in the updatecommand use it like
trspfb_UserID = Session("SCLUsername")

hope it sud work


0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

vavjeevaCommented:
you already defined the sessionparameter.. i didnt noticed that..

so you just change only this line and it sud work

in the updatecommand

instead of
trspfb_UserID = <%# Session["login_user_id"] %>

use it like

trspfb_UserID = Session("login_user_id")
0
wilson082572Author Commented:
I already tried that...
I think thats for VB
0
vavjeevaCommented:
it sud work buddy..chk this out here.
http://forums.asp.net/p/1200744/2090490.aspx#2090490

is it compilation error coming??
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vavjeevaCommented:
if your code is in C#, try the below in the updatecommand
instead of
trspfb_UserID = <%# Session["login_user_id"] %>

try with

spfb_UserID = @trspfb_UserID
0
wilson082572Author Commented:
I tried all of that...
if i put spfb_UserID = @trspfb_UserID it doesn't give me an error message but
It doesn't update the database.

thanks
0
vavjeevaCommented:
change the session parameter Type from INT to String and see how it works..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.