Public Class TeamAreaPriceTonkm
Inherits System.Web.UI.Page
Protected txtMin() As System.Web.UI.WebControls.TextBox
Protected txtMax() As System.Web.UI.WebControls.TextBox
Protected txtBprice() As System.Web.UI.WebControls.TextBox
Protected txtUprice() As System.Web.UI.WebControls.TextBox
Protected lblArea() As System.Web.UI.WebControls.Label
Protected lbl1() As System.Web.UI.WebControls.Label
Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
Protected WithEvents BtnSave As System.Web.UI.WebControls.Button
Protected lbl2() As System.Web.UI.WebControls.Label
#Region " Web 窗体设计器生成的代码 "
该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
CODEGEN: 此方法调用是 Web 窗体设计器所必需的
不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Dim objConn As New SqlConnection(strConn)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
在此处放置初始化页的用户代码
If Not IsPostBack Then
dim i as integer
for i=0 to 10
ReDim txtMin(i)
ReDim txtMax(i)
ReDim txtBprice(i)
ReDim txtUprice(i)
ReDim lblArea(i)
ReDim lbl1(i)
ReDim lbl2(i)
txtMin(i) = New TextBox()
txtMin(i).Style("width") = "40px"
txtMin(i).Text = i+20
lblArea(i) = New Label()
lblArea(i).Style("width") = "80px"
lblArea(i).Text = "<=Ga(t)<"
txtMax(i) = New TextBox()
txtMax(i).Style("width") = "40px"
txtMax(i).Text = i+40
txtBprice(i) = New TextBox()
txtBprice(i).Style("width") = "50px"
txtBprice(i).Text = 4+i
lbl1(i) = New Label()
lbl1(i).Text = "元"
txtUprice(i) = New TextBox()
txtUprice(i).Style("width") = "50px"
txtUprice(i).Text =5+i
lbl2(i) = New Label()
lbl2(i).Text = "元"
Panel1.Controls.Add(txtMin(i))
Panel1.Controls.Add(lblArea(i))
Panel1.Controls.Add(txtMax(i))
Panel1.Controls.Add(txtBprice(i))
Panel1.Controls.Add(lbl1(i))
Panel1.Controls.Add(txtUprice(i))
Panel1.Controls.Add(lbl2(i))
Panel1.Controls.Add(New LiteralControl("<br>"))
next
End If
End Sub
Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
‘我如何对上面定义的文本框 txtMin(i) 、txtMax(i)
、txtBprice(i) txtUprice(i)进行操作的记录保存到数据库
end sub
单击保存按扭,返回的错误记录是:
应用程序中的服务器错误。
--------------------------------------------------------------------------------
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 330: Response.Write(txtMax(i).Text + "**" + txtMin(i).Text)
源文件: C:\Inetpub\wwwroot\TruckInfo\TeamAreaPriceTonkm.aspx.vb 行: 330
堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
TruckInfo.TeamAreaPriceTonkm.BtnSave_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\TruckInfo\TeamAreaPriceTonkm.aspx.vb:332
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1244
太多了,
建议:1.如果用了数组的话,请确定所访问的下标是在数组长度中的(是存在的),
2.if(txtMax(i)!=null)txtMax(i).Text (C#的)
定义语句应为这样:
Protected txtMin As System.Web.UI.WebControls.TextBox()
if (txtMax(i).ToString.Trim = "") txtMax(i).Text (VB 的)
用脚本语言