问题
I have 2 image buttons, Accept and Reject. Accept button will update [status] to 1 Reject button will update [status] to 2
I had successfully use UpdateCommand to update Accept button
UpdateCommand="UPDATE [bookingschedule] SET status='1'WHERE [bookingScheduleID] = @bookingScheduleID"
But, I do not know how to set update command for Reject button since I can declared UpdateCommand once only.
UpdateCommand2="UPDATE [bookingschedule] SET status='2'WHERE [bookingScheduleID] = @bookingScheduleID" (incorrect)
What should I do to make Reject button function? Where should i put this 2nd update command line:
UpdateCommand="UPDATE [bookingschedule] SET status='2'WHERE [bookingScheduleID] = @bookingScheduleID"
I do all this coding at client side:
Accept Button:
<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>
Reject Button:
<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 datasource:
<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>
回答1:
Use a control to dynamically store/pass the status based on the button clicked
UpdateCommand="UPDATE [bookingschedule] SET status=@Status WHERE [bookingScheduleID] = @bookingScheduleID"
then add
<asp:ControlParameter Name="Status" ControlID="StatusSelectionControl" PropertyName="Text" Type="Int32" />
the propertyName should be relative to the control used - am assuming TextBox, but you can also use hidden field
来源:https://stackoverflow.com/questions/10835821/update-gridview-with-image-button