Need help with bound data
I am using a datagrid to display a list of invoices. I would like to add a field for the user to enter a payment amount for one or more of the invoices. The payment field is not in the database. I am new to ASP and cannot figure out how to do this. I have created a datatable with the database fields and this new field and have used it as the datasource for the datagrid. This worked fine and I have use the item template to display the payment field as a textbox. This works fine and the invoices appear correctly in the datagrid. The problem is that I can't figure out how to get the value(s) that are entered in the payment textbox.
The template for the column I want the user to enter the amount in looks like this:
<asp:TemplateColumn HeaderText="Amount">
<ItemTemplate>
<asp:TextBox id="tbxPmtAmount" runat="server" MaxLength="10" Text='<%# DataBinder.Eval(Container, "DataItem.PmtAmount", "{0:F}") %>' Width="100px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
I don't want the user to have to use command buttons for each row. I just want one submit button on the page if that's possible. I'm trying to use this code to retrieve the payment amount:
public sub btnSubmitClick(Sender as Object, e as EventArgs)
Dim i as Integer
Dim PmtsEntered As Boolean
Dim dttInvoices As DataTable
Dim AmountDue As Single
PmtsEntered = False
dttInvoices = Ctype(dtgInvoices.DataSource, DataTable)
For i = 0 To dttInvoices.Rows.Count - 1
AmountDue = CType(dttInvoices.Rows(i)("AmountDue"), Single)
If Trim(dttInvoices.Rows(i)("PmtAmount")) = "" Then
ElseIf Not IsNumeric(dttInvoices.Rows(i)("PmtAmount")) Then
lblWrn.Text = "Payment amount must be numeric"
Exit For
ElseIf AmountDue And CType(dttInvoices.Rows(i)("PmtAmount"), Single) < 0 Then
lblWrn.Text = "Payment must be a positive amount"
Else
PmtsEntered = True
End If
Next
If lblWrn.Text = "" And Not PmtsEntered Then
lblWrn.Text = "No invoices selected for Payment"
End If
end sub
I am receiving this compile error on the FOR statement:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. I have no idea what I am doing wrong.
|