I have an Ordering system showing Orders that have been received and also orders that are outstanding. If the Order is received and the checkbox is then checked I would like to add the date to the database when the order was received. Obviously I would only like to add the date to the row that has been checked. Thanks in advance.
relevant HTML as follows:
<asp:GridView ID="gvOpenOrders" runat="server" AutoGenerateColumns="False" Width="100%" CellPadding="4" ForeColor="#333333"
GridLines="None" DataKeyNames="PurchaseOrderID" AllowPaging="True" AllowSorting="True"
OnSorting="gvOpenOrders_Sorting" EnableViewState="true" OnPageIndexChanging="OnPageIndexChanging" PageSize="15" ViewStateMode="Enabled">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Is Received" SortExpression="IsReceived">
<ItemTemplate>
<asp:CheckBox ID="chkRcvd" runat="server" AutoPostBack="true" Checked='<%# Bind("IsReceived") %>' Enabled='<%# Eval("IsReceived") = False %>' OnCheckedChanged="chkRcvd_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
I am currently updating the database when a Update Received button is clicked, see below:
Protected Sub btnUpdateReceived_Click(sender As Object, e As EventArgs) Handles btnUpdateReceived.Click
con.Open()
For Each row As GridViewRow In gvOpenOrders.Rows
Dim purchaseOrderID As Integer = Convert.ToInt32(gvOpenOrders.DataKeys(row.RowIndex).Values(0))
Dim isReceived As Boolean = TryCast(row.FindControl("chkRcvd"), CheckBox).Checked
cmd.CommandText = "usp_UpdatePurchaseOrder"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("@OrderID", purchaseOrderID)
cmd.Parameters.AddWithValue("@IsReceived", isReceived)
cmd.ExecuteNonQuery()
Next
con.Close()
Response.Redirect(Request.Url.AbsoluteUri)
End Sub
I know that there is a checkbox_CheckedChanged event but I am unsure how to use it.
Aucun commentaire:
Enregistrer un commentaire