Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datalist Row ID

Status
Not open for further replies.

tjherman

Programmer
Jun 19, 2006
68
US
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!
 
The code you have is almost there.. You need to place it in the ItemDataBound event of the datalist. and you can use the arguments variable e to get the reference to the row.

 
But if I'm wanting to run the code, for example, on text changed of a field on one of the rows, how does the ItemDataBound event get called?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top