0

我有 2 个图像按钮,接受和拒绝。接受按钮将 [status] 更新为 1 拒绝按钮将 [status] 更新为 2

我已成功使用 UpdateCommand 更新接受按钮

UpdateCommand="UPDATE [bookingschedule] SET status='1'WHERE [bookingScheduleID] = @bookingScheduleID"

但是,我不知道如何为拒绝按钮设置更新命令,因为我只能声明一次 UpdateCommand。

UpdateCommand2="UPDATE [bookingschedule] SET status='2'WHERE [bookingScheduleID] = @bookingScheduleID" (incorrect)

我应该怎么做才能使拒绝按钮功能?我应该把这个第二个更新命令行放在哪里:

UpdateCommand="UPDATE [bookingschedule] SET status='2'WHERE [bookingScheduleID] = @bookingScheduleID"

我在客户端完成所有这些编码:

接受按钮:

<asp:TemplateField HeaderText="Action Approve">
<ItemTemplate>
<asp:ImageButton runat="server" ID="UpdateCommand"
  CommandName="update" ImageUrl="~/images/accept.png"
  OnClientClick="if (!window.confirm('Are you sure you want to approve this booking?')) return false;" />
</ItemTemplate>
</asp:TemplateField>

拒绝按钮:

<asp:TemplateField HeaderText="Action Reject">
<ItemTemplate>
<asp:ImageButton runat="server" ID="UpdateCommand" CommandName="update" OnClick="reject"
  ImageUrl="~/images/reject.png"
  OnClientClick="if (!window.confirm('Are you sure you want to reject this booking?')) return false;" />
</ItemTemplate>
</asp:TemplateField>

SQL 数据源:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
            SelectCommand="SELECT [bookingScheduleID], [eventTitle], [week1], [week2], [week3], [week4], [week5], [week6], [week7], [week8], [exhibitorname], [boothAlias], [category], [status], [dateBook],[custNo] FROM [booking_all]" 
            UpdateCommand="UPDATE [bookingschedule] SET status='1'WHERE [bookingScheduleID] = @bookingScheduleID"
            >
        </asp:SqlDataSource>
        <UpdateParameters>
        <asp:Parameter Name="bookingScheduleID" Type="Int32" />
        </UpdateParameters> 
4

1 回答 1

0

使用控件根据单击的按钮动态存储/传递状态

UpdateCommand="UPDATE [bookingschedule] SET status=@Status WHERE [bookingScheduleID] = @bookingScheduleID"

然后加

<asp:ControlParameter Name="Status" ControlID="StatusSelectionControl" PropertyName="Text" Type="Int32" />

propertyName 应该与使用的控件相关-假设是 TextBox,但您也可以使用隐藏字段

于 2012-05-31T15:08:57.887 回答