I have a page that has a formview (for the parent table data) and a datalist control (for the child table data). For a single check request record, for example, 3 rows of products may be displaying in the datalist control. I have fields for Quantity, Cost and Total Cost. I have code that should multiple the quantity value by the cost value to get the Total Cost value. This works fine if I'm using a formview control but does not work with the datalist control -- I'm assuming that this is because I'm not identifying the ID of the datalist row that I want to work with.
Here is my existing code:
Dim MyQty As TextBox = CType(DataList1.FindControl("txtQuantity"), TextBox)
Dim MyUnit As TextBox = CType(DataList1.FindControl("txtUnitCost"), TextBox)
Dim MyTotal As TextBox = CType(DataList1.FindControl("txtTotalCost"), TextBox)
MyTotal.Text = MyQty.Text * MyUnit.Text
The error tells me "Object reference not set to an instance of an object." Again, this works for formview objects but not for the datalist objects.
Can anyone tell me how to rewrite this? I'm assuming I need to get the ID of the row before I can refer to it but I don't know how to do this. I'm using VB.
Thanks!
Here is my existing code:
Dim MyQty As TextBox = CType(DataList1.FindControl("txtQuantity"), TextBox)
Dim MyUnit As TextBox = CType(DataList1.FindControl("txtUnitCost"), TextBox)
Dim MyTotal As TextBox = CType(DataList1.FindControl("txtTotalCost"), TextBox)
MyTotal.Text = MyQty.Text * MyUnit.Text
The error tells me "Object reference not set to an instance of an object." Again, this works for formview objects but not for the datalist objects.
Can anyone tell me how to rewrite this? I'm assuming I need to get the ID of the row before I can refer to it but I don't know how to do this. I'm using VB.
Thanks!