wilson082572
asked on
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.
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.
please explain your question in detail. post your source code for more understanding.
ASKER
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(tx tUserName. Text, txtPassword.Text);
DataTable dt = new DataTable();
dt.Load(dr, LoadOption.OverwriteChange s);
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"].ToStr ing();
...
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.
the code in the Login.aspx.cs is:
protected void btnLogin_Click(object sender, EventArgs e)
{
IDataReader dr = data_access.Login_Check(tx
DataTable dt = new DataTable();
dt.Load(dr, LoadOption.OverwriteChange
DataTableReader dtr = dt.CreateDataReader();
if (dtr.HasRows)
{
dtr.Read();
Session["authenticated"] = true;
Session["login_user_id"] = Convert.ToInt32(dtr["user_
Session["user_level_id"] = Convert.ToInt32(dtr["user_
Session["user_fullname"] = dtr["user_fullname"].ToStr
...
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>
<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>
yeah.. add sessionparameter and use that ..
<asp:SessionParameter Name="SessionUserID" SessionField="login_user_i d" Type="String" />
and in the updatecommand use it like
trspfb_UserID = Session("SCLUsername")
hope it sud work
<asp:SessionParameter Name="SessionUserID" SessionField="login_user_i
and in the updatecommand use it like
trspfb_UserID = Session("SCLUsername")
hope it sud work
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")
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")
ASKER
I already tried that...
I think thats for VB
I think thats for VB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
instead of
trspfb_UserID = <%# Session["login_user_id"] %>
try with
spfb_UserID = @trspfb_UserID
ASKER
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
if i put spfb_UserID = @trspfb_UserID it doesn't give me an error message but
It doesn't update the database.
thanks
change the session parameter Type from INT to String and see how it works..