asked on
Protected Sub gvInspectionDetails_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvInspectionDetails.RowEditing
' If Loading Then
'Else
gvInspectionDetails.EditIndex = e.NewEditIndex
gvInspectionDetails.DataSource = myDS.Tables(1).DefaultView
gvInspectionDetails.DataBind()
'End If
End Sub
Private Sub gvInspectionDetails_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvInspectionDetails.RowUpdating
myDS.Tables(1).AcceptChanges()
gvInspectionDetails.EditIndex = -1
gvInspectionDetails.DataSource = myDS.Tables(1)
gvInspectionDetails.DataBind()
End Sub
ASKER
Imports System.Data.SqlClient
Imports System.Data
Imports System.IO
Partial Public Class MOInspectionsEdit
Inherits System.Web.UI.Page
Dim myWO As String = ""
Dim myPropertyID As String = ""
Dim myDA As New SqlDataAdapter
Shared myDS As New DataSet
Private Const myConnStr As String = "SERVER=xx.xx.xx.xx,8433;Database=AptGalleryInspections;uid=sa;pwd=sh4207"
Dim myconn As New SqlConnection(myConnStr)
Dim Loading As Boolean = True
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
myWO = Request.QueryString("WO")
myPropertyID = Request.QueryString("PropName")
gvInspectionDetails.AlternatingRowStyle.BackColor = Drawing.Color.White
initializeForm()
Else
End If
Loading = False
End Sub
Protected Sub initializeForm()
Dim i As Integer = 0
Dim myCMD As New SqlCommand
Dim myCMD2 As New SqlCommand
With myCMD
.Connection = myconn
.CommandText = "SELECT * FROM inspectionMaster WHERE wo_number='" & myWO & "'"
.CommandType = CommandType.Text
End With
With myCMD2
.Connection = myconn
.CommandText = "SELECT * FROM inspectiondetails WHERE wo_number='" & myWO & "' ORDER BY ItemGroup"
.CommandType = CommandType.Text
End With
Try
myconn.Open()
myDA.SelectCommand = myCMD
myDA.Fill(myDS, "Master")
myDA.SelectCommand = myCMD2
myDA.Fill(myDS, "Details")
myconn.Close()
Dim myCol As New DataColumn
myCol.ColumnName = "UpDateCost"
myCol.DefaultValue = False
myDS.Tables(1).Columns.Add(myCol)
Dim myCol2 As New DataColumn
myCol2.ColumnName = "UpDatePrice"
myCol2.DefaultValue = False
myDS.Tables(1).Columns.Add(myCol2)
myDS.Tables(1).AcceptChanges()
' myDS.Tables(1).DefaultView.Sort = "itemgroup"
gvInspectionDetails.DataSource = myDS.Tables(1)
gvInspectionDetails.DataBind()
lblWoNumber.Text = myDS.Tables(0).Rows(0).Item(1)
lblWoDescrip.Text = myDS.Tables(0).Rows(0).Item(2)
Catch ex As Exception
End Try
End Sub
Private Sub gvInspectionDetails_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gvInspectionDetails.RowCancelingEdit
myDS.Tables(1).RejectChanges()
gvInspectionDetails.EditIndex = -1
gvInspectionDetails.DataSource = myDS.Tables(1)
gvInspectionDetails.DataBind()
End Sub
Protected Sub gvInspectionDetails_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvInspectionDetails.RowEditing
' If Loading Then
'Else
gvInspectionDetails.EditIndex = e.NewEditIndex
gvInspectionDetails.DataSource = myDS.Tables(1).DefaultView
gvInspectionDetails.DataBind()
'End If
End Sub
Private Sub gvInspectionDetails_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvInspectionDetails.RowUpdating
' Dim myText As TextBox
'myText = dgGoalsAdd.Rows(e.RowIndex).FindControl("txtGoals")
myDS.Tables(1).AcceptChanges()
gvInspectionDetails.EditIndex = -1
' myDS.Tables(0).Rows(e.RowIndex).Item(4) = myText.Text
gvInspectionDetails.DataSource = myDS.Tables(1)
gvInspectionDetails.DataBind()
End Sub
Protected Sub gvInspectionDetails_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles gvInspectionDetails.SelectedIndexChanged
End Sub
End Class
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="Inspections.Master" CodeBehind="MOInspectionsEdit.aspx.vb" Inherits="eSiteCompanionDevelopement.MOInspectionsEdit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<table style="width: 100%">
<tr>
<td style="width: 181px">
WO. Number: <asp:Label ID="lblWoNumber" runat="server" Text='Label1'></asp:Label>
</td>
<td colspan="2">
Wo. Description:
<asp:Label ID="lblWoDescrip" runat="server" Text="Label"></asp:Label>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td style="width: 181px">
</td>
<td style="width: 173px">
</td>
<td style="width: 140px">
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td style="width: 181px">
</td>
<td style="width: 173px">
</td>
<td style="width: 140px">
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td colspan="6">
<asp:GridView ID="gvInspectionDetails" runat="server" Width="967px"
AutoGenerateColumns="False" AutoGenerateEditButton="True">
<Columns>
<asp:BoundField DataField="ItemID" HeaderText="Item ID" ReadOnly="True">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="itemGroup" HeaderText="Room " ReadOnly="True">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="ItemDescription" HeaderText="Description"
ReadOnly="True">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="ItemQty" HeaderText="Quantiy">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="ItemCost" DataFormatString="{0:c}" HeaderText="Cost"
HtmlEncode="False">
<ItemStyle Width="75px" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="ItemPrice" DataFormatString="{0:c}"
HeaderText="Price">
<ItemStyle Width="75px" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="ResidentCharge" HeaderText="Type">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:CheckBoxField DataField="UpdateCost" HeaderText="Update Cost">
<ItemStyle Width="50px" Wrap="False" />
</asp:CheckBoxField>
<asp:CheckBoxField DataField="UpdatePrice" HeaderText="Update Price">
<ItemStyle Width="50px" Wrap="False" />
</asp:CheckBoxField>
</Columns>
</asp:GridView>
<br />
<br />
<br />
</td>
</tr>
<tr>
<td colspan="6">
</td>
</tr>
</table>
</asp:Content>
ASKER
ASKER
The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications
TRUSTED BY
For starters your events should update the dataset directly before binding.
Asp.net is stateless and your code is controling where the binding is happening, thus whatever current contents of the dataset are loaded again to gvInspectionDetails.
Pseudo code follows:
Protected Sub gvInspectionDetails_RowEdi
'Assing changes from gvInspectionDetails to myDS.Tables(1)
gvInspectionDetails.EditIn
gvInspectionDetails.DataSo
gvInspectionDetails.DataBi
End Sub