Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

c# - How to include a session variable in the update command of a datagrid asp.net

Super Beginner Here:)

My original scope was a simple datagrid where I could use the prebuilt vs2019 asp.net delete and edit properties of the datagrid.

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="EditItemSoftDelete.aspx.cs" Inherits="ProcessingSchedule8.WebForm5" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

<p>
    <br />
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ActivityID" DataSourceID="SqlDataSource1">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
            <asp:BoundField DataField="Division" HeaderText="Division" SortExpression="Division" />
            <asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department" />
            <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
            <asp:BoundField DataField="Start" HeaderText="Start" SortExpression="Start" />
            <asp:BoundField DataField="End" HeaderText="End" SortExpression="End" />
            <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
            <asp:BoundField DataField="Note" HeaderText="Note" SortExpression="Note" />
            <asp:BoundField DataField="Grouping" HeaderText="Grouping" SortExpression="Grouping" />
            <asp:CheckBoxField DataField="Updated" HeaderText="Updated" SortExpression="Updated" />
            <asp:BoundField DataField="Format" HeaderText="Format" SortExpression="Format" />
            <asp:BoundField DataField="ActivityID" HeaderText="ActivityID" InsertVisible="False" ReadOnly="True" SortExpression="ActivityID" />
            <asp:CheckBoxField DataField="EditFlag" HeaderText="EditFlag" SortExpression="EditFlag" />
            <asp:CheckBoxField DataField="DeleteFlag" HeaderText="DeleteFlag" SortExpression="DeleteFlag" />
            <asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" />
            <asp:BoundField DataField="EditDate" HeaderText="EditDate" SortExpression="EditDate" />
            <asp:BoundField DataField="DeleteDate" HeaderText="DeleteDate" SortExpression="DeleteDate" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ProcessingScheduleDevlConnectionString %>" DeleteCommand="UPDATE [Activities] SET [Updated] = 1, [EditFlag] = 1, [DeleteFlag] = 1, **[UserID] = This is where I want to get and put the anumber into the table**  WHERE [ActivityID] = @ActivityID" InsertCommand="INSERT INTO [Activities] ([Year], [Division], [Department], [Type], [Start], [End], [Description], [Note], [Grouping], [Updated], [Format], [EditFlag], [DeleteFlag], [UserID], [EditDate], [DeleteDate]) VALUES (@Year, @Division, @Department, @Type, @Start, @End, @Description, @Note, @Grouping, @Updated, @Format, @EditFlag, @DeleteFlag, @UserID, @EditDate, @DeleteDate)" SelectCommand="SELECT * FROM [Activities]" UpdateCommand="UPDATE [Activities] SET [Year] = @Year, [Division] = @Division, [Department] = @Department, [Type] = @Type, [Start] = @Start, [End] = @End, [Description] = @Description, [Note] = @Note, [Grouping] = @Grouping, [Updated] = @Updated, [Format] = @Format, [EditFlag] = @EditFlag, [DeleteFlag] = @DeleteFlag, [UserID] = @UserID, [EditDate] = @EditDate, [DeleteDate] = @DeleteDate WHERE [ActivityID] = @ActivityID">
        <DeleteParameters>
            <asp:Parameter Name="ActivityID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Year" Type="String" />
            <asp:Parameter Name="Division" Type="String" />
            <asp:Parameter Name="Department" Type="String" />
            <asp:Parameter Name="Type" Type="String" />
            <asp:Parameter DbType="Date" Name="Start" />
            <asp:Parameter DbType="Date" Name="End" />
            <asp:Parameter Name="Description" Type="String" />
            <asp:Parameter Name="Note" Type="String" />
            <asp:Parameter Name="Grouping" Type="String" />
            <asp:Parameter Name="Updated" Type="Boolean" />
            <asp:Parameter Name="Format" Type="String" />
            <asp:Parameter Name="EditFlag" Type="Boolean" />
            <asp:Parameter Name="DeleteFlag" Type="Boolean" />
            <asp:Parameter Name="UserID" Type="String" />
            <asp:Parameter DbType="Date" Name="EditDate" />
            <asp:Parameter DbType="Date" Name="DeleteDate" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="Year" Type="String" />
            <asp:Parameter Name="Division" Type="String" />
            <asp:Parameter Name="Department" Type="String" />
            <asp:Parameter Name="Type" Type="String" />
            <asp:Parameter DbType="Date" Name="Start" />
            <asp:Parameter DbType="Date" Name="End" />
            <asp:Parameter Name="Description" Type="String" />
            <asp:Parameter Name="Note" Type="String" />
            <asp:Parameter Name="Grouping" Type="String" />
            <asp:Parameter Name="Updated" Type="Boolean" />
            <asp:Parameter Name="Format" Type="String" />
            <asp:Parameter Name="EditFlag" Type="Boolean" />
            <asp:Parameter Name="DeleteFlag" Type="Boolean" />
            <asp:Parameter Name="UserID" Type="String" />
            <asp:Parameter DbType="Date" Name="EditDate" />
            <asp:Parameter DbType="Date" Name="DeleteDate" />
            <asp:Parameter Name="ActivityID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
</p>
</asp:Content>

Now my boss wants me to do a soft delete instead and also insert the user's ID that they entered on the login page. I am sure it is ugly but so far I simply changed the delete command to an update statement and I am now correctly setting the update and delete flags and they are working in the table, exciting!

Now I can't understand how to get the useriD (simple text box, we call it a number) which the user entered in the login page (a different web form) and use that value in the update.

Thanks so much.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...