条件更新命令

时间:2016-12-13 07:05:03

标签: c# sql asp.net webforms

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" AutoGenerateEditButton="true">
    <Columns>

        <asp:BoundField DataField="Job" HeaderText="Job" SortExpression="Job" />
        <asp:BoundField DataField="Job_Operation" HeaderText="Job_Operation" SortExpression="Job_Operation" />

        <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />

        <asp:CommandField ShowEditButton="True" />

    </Columns>

</asp:GridView>

select命令返回以下行:

Job  Job_Operation Status

5294 56250 C 11/29/2016 Edit 

5294 56251 O 12/9/2016 Edit 


            SelectCommand="SELECT [Job],[Job_Operation],[Status], FROM [Job_Operation] WHERE ([Job] = @JobNum)"  


            UpdateCommand="UPDATE Job_Operation set status = @Status where (Job = @Job) and (Job_Operation = @Job_Operation) UPDATE Job_Operation where (Job = @Job) and (Job_Operation = @Job_Operation)

            <SelectParameters>
                <asp:FormParameter FormField="JobNum" Name="JobNum" />
            </SelectParameters>
        </asp:SqlDataSource>

如果用户尝试在任何行上将状态字段从“O”更改为“C”(如果下一个操作中的任何一个是“C”),我想添加一个阻止更新命令运行的条件。

也许将选择结果放入一个数组并循环查找大于当前选择的job_operations,查找值为“C”的“status”字段

这是用C#编程的

1 个答案:

答案 0 :(得分:0)

如果下一行未完成,我最终使用Jquery创建警报:

  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js" type="text/javascript"></script>
<script>
    $(function () {
        $("a").click(function () {
            var row = $(this).closest('tr');
            var index = row.index();
            //this could find the prev value
            var prev = row.prev().find("td:eq(3) span").html();
            if (index == 1) {
                return true;
            } else {
                if (prev.trim() != "C") {
                    alert("The previous operation is NOT COMPLETE");
                    return false
                } else {
                    return true;
                }
            }
        });
    });
</script>