我创建的网络表单比我在下面列出的内容更复杂。
最重要的是,我正在更新GridView,并且我希望根据第一个GridView上的GridView更改自己进行第二次Gridview更新!
请帮忙!我已尝试在GridView2.DataBind()
方法中包含updateNumber()
行,但我收到实例引用错误或类似内容。我已经被困在这几天了!
我更新了GridView1
中的号码,它使用新号码刷新和更新,但不是GridView2,它应该在GridView1
上显示更新的号码(是的,我需要GridView2
致电GetUpdateNumber()
GridView2
仍然会显示旧号码......更新前的号码GridView1
以下是
背后的代码 Option Strict On
Imports Team.MyWebProject
Public Class Blah
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myNumberClass As New myClass1
Dim mylist As New List(Of myClass1)
Try
If (Not IsPostBack) Then
If Session("Number") Is Nothing Then
myNumberClass.number = 2
mylist.Add(myNumberClass)
Session("Number") = mylist
Else
myNumberClass = Nothing
mylist = CType(Session("Number"), List(Of myClass1))
End If
Else
mylist = CType(Session("Number"), List(Of myClass1))
End If
Catch ex As Exception
MsgBox(ex.Message & "/Blah.aspx.vb Page_Load")
End Try
End Sub
Public Function getNumber() As List(Of myClass1)
Try
Dim mylist As List(Of myClass1) = CType(Session("Number"), List(Of myClass1))
Return mylist
Catch ex As Exception
MsgBox(ex.Message & "/Blah.aspx.vb GetNumber")
End Try
End Function
Public Function getUpdatedNumber() As List(Of myClass1)
Try
Dim mylist As List(Of myClass1) = CType(Session("Number"), List(Of myClass1))
Return mylist
Catch ex As Exception
MsgBox(ex.Message & "/Blah.aspx.vb GetUpdateNumber")
End Try
End Function
Public Sub updateNumber(ByVal number As Integer)
Try
Dim mylist As List(Of myClass1) = CType(Session(Number"), List(Of myClass1))
Dim LoopIndex As New Integer
LoopIndex = 0
For Each Match In mylist
mylist(LoopIndex).Number = number
LoopIndex += 1
Next
Session("Number") = mylist
Catch ex As Exception
MsgBox(ex.Message & "blah.aspx.vb updateNumber")
End Try
End Sub
Protected Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles GridView1.RowCommand
End Sub
Protected Sub GridView1_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles GridView1.RowEditing
End Sub
Protected Sub GridView1_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Try
Catch ex As Exception
MsgBox(ex.Message & "Blah.aspx.vb GridView13_RowUpdating()")
End Try
End Sub
Protected Sub GridView2_DataBinding(sender As Object, e As EventArgs) Handles GridView2.DataBinding
Try
Dim mylist As List(Of myClass1) = CType(Session("Number"), List(Of myClass1))
getUpdatedNumber()
Catch ex As Exception
MsgBox(ex.Message & "Blah.aspx GridView2_Databinding()")
End Try
End Sub
End Class
Here is the myClass1.vb class:
Namespace MyWebProject
Public Class myClass1
Private _number As Integer
Public Sub New()
_number = 0
End Sub
Public Sub New(ByVal number As Integer)
_number = number
End Sub
Public Property Number() As Integer
Get
Return _number
End Get
Set(value As Integer)
_number = value
End Set
End Property
End Class
End Namespace
And here is the MarkUp page:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Blah.aspx.vb" Inherits="GridViewUpdateTest.Blah" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="Number" HeaderText="Number" SortExpression="Number" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="getNumber" TypeName="GridViewUpdateTest.Blah" UpdateMethod="updateNumber">
<UpdateParameters>
<asp:Parameter Name="number" Type="Int32" />
</UpdateParameters>
</asp:ObjectDataSource>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource2">
<Columns>
<asp:BoundField DataField="Number" HeaderText="Number" SortExpression="Number" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="getUpdatedNumber" TypeName="GridViewUpdateTest.Blah"></asp:ObjectDataSource>
</form>
</body>
</html>