我不确定我做错了什么,我正在尝试向Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not (Page.IsPostBack) Then
SetInitialRow()
QuotaionGrid.Visible = False
Buttons.Visible = False
ClientDetails.Visible = False
txtClientNumber.Enabled = False
txtName.Enabled = False
txtSurname.Enabled = False
Search.Visible = True
End If
End Sub
Private Sub SetInitialRow()
Dim dt As New DataTable()
dt.Columns.Add("RowId", GetType(Integer))
dt.Columns.Add("Quantity", GetType(String))
dt.Columns.Add("StockCode", GetType(String))
dt.Columns.Add("Description", GetType(String))
dt.Columns.Add("UnitPrice", GetType(String))
dt.Columns.Add("TotalItemCost", GetType(String))
Dim dr As DataRow = dt.NewRow()
dr("RowId") = 1
dr("Quantity") = String.Empty
dr("StockCode") = String.Empty
dr("Description") = String.Empty
dr("UnitPrice") = String.Empty
dr("TotalItemCost") = String.Empty
dt.Rows.Add(dr)
ViewState("Curtbl") = dt
grdQuotation.DataSource = dt
grdQuotation.DataBind()
End Sub
Public Sub AddNewRowToGrid()
Dim rowIndex As Integer = 0
If ViewState("Curtbl") IsNot Nothing Then
Dim dt As DataTable = DirectCast(ViewState("Curtbl"), DataTable)
Dim drCurrentRow As DataRow = Nothing
If dt.Rows.Count > 0 Then
For i As Integer = 1 To dt.Rows.Count
Dim txtQuantity As TextBox = DirectCast(grdQuotation.Rows(rowIndex).Cells(1).FindControl("txtQuantity"), TextBox)
Dim txtStockCode As TextBox = DirectCast(grdQuotation.Rows(rowIndex).Cells(2).FindControl("txtStockCode"), TextBox)
Dim txtDescription As TextBox = DirectCast(grdQuotation.Rows(rowIndex).Cells(3).FindControl("txtDescription"), TextBox)
Dim txtUnitPrice As TextBox = DirectCast(grdQuotation.Rows(rowIndex).Cells(4).FindControl("txtUnitPrice"), TextBox)
Dim txtTotalItemCost As TextBox = DirectCast(grdQuotation.Rows(rowIndex).Cells(5).FindControl("txtTotalItemCost"), TextBox)
drCurrentRow = dt.NewRow()
drCurrentRow("RowId") = i + 1
dt.Rows(i - 1)("Quantity") = txtQuantity.Text
dt.Rows(i - 1)("StockCode") = txtStockCode.Text
dt.Rows(i - 1)("Description") = txtDescription.Text
dt.Rows(i - 1)("UnitPrice") = txtUnitPrice.Text
dt.Rows(i - 1)("TotalItemCost") = txtTotalItemCost.Text
'dt.Rows(i - 1)("TotalItemCost") = txtTotalItemCost.Text
rowIndex += 1
Next
dt.Rows.Add(drCurrentRow)
ViewState("Curtbl") = dt
grdQuotation.DataSource = dt
grdQuotation.DataBind()
End If
Else
Response.Write("ViewState Value is Null")
End If
SetOldData()
End Sub
Private Sub SetOldData()
Dim rowIndex As Integer = 0
If ViewState("Curtbl") IsNot Nothing Then
Dim dt As DataTable = DirectCast(ViewState("Curtbl"), DataTable)
If dt.Rows.Count > 0 Then
For i As Integer = 0 To dt.Rows.Count - 1
Dim txtQuantity As TextBox = DirectCast(grdQuotation.Rows(rowIndex).Cells(1).FindControl("txtQuantity"), TextBox)
Dim txtStockCode As TextBox = DirectCast(grdQuotation.Rows(rowIndex).Cells(2).FindControl("txtStockCode"), TextBox)
Dim txtDescription As TextBox = DirectCast(grdQuotation.Rows(rowIndex).Cells(3).FindControl("txtDescription"), TextBox)
Dim txtUnitPrice As TextBox = DirectCast(grdQuotation.Rows(rowIndex).Cells(4).FindControl("txtUnitPrice"), TextBox)
Dim txtTotalItemCost As TextBox = DirectCast(grdQuotation.Rows(rowIndex).Cells(5).FindControl("txtTotalItemCost"), TextBox)
txtQuantity.Text = dt.Rows(i)("Quantity").ToString
txtStockCode.Text = dt.Rows(i)("StockCode").ToString()
txtDescription.Text = dt.Rows(i)("Description").ToString()
txtUnitPrice.Text = dt.Rows(i)("UnitPrice").ToString
txtTotalItemCost.Text = dt.Rows(i)("TotalItemCost").ToString
rowIndex += 1
Next
End If
End If
End Sub
Protected Sub cmdAdd_Click(ByVal sender As Object, ByVal e As EventArgs)
AddNewRowToGrid()
End Sub
Protected Sub grdQuotation_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
If ViewState("Curtbl") IsNot Nothing Then
Dim dt As DataTable = DirectCast(ViewState("Curtbl"), DataTable)
Dim drCurrentRow As DataRow = Nothing
Dim rowIndex As Integer = Convert.ToInt32(e.RowIndex)
If dt.Rows.Count > 1 Then
dt.Rows.Remove(dt.Rows(rowIndex))
drCurrentRow = dt.NewRow()
ViewState("Curtbl") = dt
grdQuotation.DataSource = dt
grdQuotation.DataBind()
For i As Integer = 0 To grdQuotation.Rows.Count - 2
grdQuotation.Rows(i).Cells(0).Text = Convert.ToString(i + 1)
Next
SetOldData()
End If
End If
End Sub
添加一个新行,并在此站点上复制了代码示例以进行复制,但仍无法正常工作,我收到了附加的错误jpeg,陈述:
在Cloud.dll中发生了类型'System.NullReferenceException'的异常,但未在用户代码中处理“”附加信息:对象引用未设置为对象的实例。“
请帮忙。
我所包含的网页代码:
public static class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
}
...
}