Protected Sub btnVoid_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVoid.Click
Dim DBConn As New SqlConnection(ConfigurationManager.ConnectionStrings("PurchaseReqConnectionString").ConnectionString)
Dim DBCmd As New SqlCommand
Try
Dim row As GridViewRow = Me.GridView1.SelectedRow
Dim vReqID As Integer = row.Cells(1).Text
Dim sql As String
sql = "UPDATE Items SET Quantity = 0 WHERE ReqID = @ReqID" 'ItemID = @ItemID and ReqID = @ReqID"
DBConn.Open()
'Add UPDATE Statement
DBCmd = New SqlCommand(sql, DBConn)
'Add Database Parameters
DBCmd.Parameters.Add("@ReqID", SqlDbType.Int).Value = vReqID
DBCmd.ExecuteNonQuery()
Catch exp As Exception
Response.Write(exp.Message)
Label1.Text = exp.Message
End Try
'Close Database connection
DBCmd.Dispose()
DBConn.Close()
DBConn = Nothing
GridView2.DataBind()
End Sub
<asp:GridView ID="GridView2" runat="server" AllowSorting="True" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="ItemID" DataSourceID="SqlDataSource2" ForeColor="#333333"
ShowFooter="True">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:CommandField ShowEditButton="True" UpdateText="Save" />
<asp:BoundField DataField="ItemID" HeaderText="ItemID" InsertVisible="False" ReadOnly="True"
SortExpression="ItemID" Visible="False" />
<asp:BoundField DataField="ItemNumber" HeaderText="Item #" SortExpression="ItemNumber" ReadOnly="true" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="ReqID" HeaderText="Requisition" SortExpression="ReqID" ReadOnly="true" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Quantity" HeaderText="Qty" SortExpression="Quantity" >
<ControlStyle Width="50px" />
<ItemStyle HorizontalAlign="Right" Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="UnitPrice" DataFormatString="{0:c}" HeaderText="Unit Price" ApplyFormatInEditMode="false"
HtmlEncode="False" SortExpression="UnitPrice" >
<ControlStyle Width="50px" />
<ItemStyle HorizontalAlign="Right" Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="SubTotal" DataFormatString="{0:c}" HeaderText="SubTotal" ReadOnly="true"
HtmlEncode="False" SortExpression="SubTotal" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="ModifiedBy" HeaderText="Modified By" SortExpression="ModifiedBy"
ReadOnly="True" >
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="DateModified" HeaderText="Date Modified" SortExpression="DateModified"
DataFormatString="{0:d}" HtmlEncode="False" ReadOnly="True" >
<ItemStyle Wrap="False" HorizontalAlign="Right" />
</asp:BoundField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#FF99FF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
ASKER
ASKER
End Try
'Close Database connection
DBCmd.Dispose()
DBConn.Close()
DBConn = Nothing
SqlDataSource2.Select(DataSourceSelectArguments.Empty)
GridView2.DataBind()
'GridView2.EditIndex = 0 <-- this puts Item #1 into Edit Mode and if I just click Update everything updates like it's supposed to, but it's commented out because it only affects one item.
End Sub
ASKER
Protected Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
' add the UnitPrice and QuantityTotal to the running total variables
priceTotal += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, _
"SubTotal"))
quantityTotal += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, _
"Quantity"))
ElseIf e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells(0).Text = "Totals:"
' for the Footer, display the running totals
e.Row.Cells(7).Text = priceTotal.ToString("c")
e.Row.Cells(4).Text = quantityTotal.ToString("d")
e.Row.Cells(7).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(4).HorizontalAlign = HorizontalAlign.Right
e.Row.Font.Bold = True
' Grab the ReqID from column 3 and total price. Send them to Requisitions Table.
iReqID = GridView1.SelectedValue 'CType(e.Row.Cells(3).TabIndex, Integer)
''I inserted the two lines below to update the total price field in the Requisitions table, but they execute too many time. Should only fire once at the end.
Call SendTotalToRequisition(priceTotal, iReqID)
GridView1.DataBind()
End If
End Sub
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.
TRUSTED BY
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.select.aspx