Correct use of class vs ID in table with data

motpaydayHart

New Member
Bear in mind, I'm new to client-side scripting, learning my way through..I need to create a page with tabular data and give user ability to click on specific link to bring modal popup and submit request.I'm placing this form into DIV and show it using jQuery, no problem.For the 'table' I have dilemma on how to hook up click and data best way. I tend to do it with classes, but then my HTML look this:\[code\]<ItemTemplate> <tr> <td class="tripId"><%# DataBinder.Eval(Container.DataItem, "TripId")%></td> <td class="pickupDate"><%# DataBinder.Eval(Container.DataItem, "PickupDate", "{0:MM/dd/yy}")%></td> <td class="from"><%# DataBinder.Eval(Container.DataItem, "FromCity")%>, <%# DataBinder.Eval(Container.DataItem, "FromState")%></td> <td class="deliveryDate"><%# DataBinder.Eval(Container.DataItem, "DeliveryDate", "{0:MM/dd/yy}")%></td> <td class="to"><%# DataBinder.Eval(Container.DataItem, "ToCity")%>, <%# DataBinder.Eval(Container.DataItem, "ToState")%></td> <td class="weight"><%# DataBinder.Eval(Container.DataItem, "Weight")%></td> <td><%# DataBinder.Eval(Container.DataItem, "LoadedMiles")%></td> <td><%# DataBinder.Eval(Container.DataItem, "RequiredEquipment")%></td> <td><a href="http://stackoverflow.com/questions/15754242/#" class="inquireLink"><strong>Inquire now</strong></a></td> </tr></ItemTemplate>\[/code\]In javascript I hook to all hrefs like this:\[code\]// Hookup link events to handle modal popup$(".inquireLink").on("click", function (event) { event.preventDefault(); inquireAboutTrip($(this));});function inquireAboutTrip($link) { // Link located on <TR> so we can traverse up and then into each cell to get data}\[/code\]So, I can traverse up to TR from link and than into each CLASS to find data inside TD. Then I can use this data on a form as I need. There is 2 problems: VS2012 complains about all those classes being undefined (of course they are not on CSS). Another problem is that for each row I have this repitition of markup.. I want it cleaner.I understand that if I use jQuery I can rely on order of TDs inside TR. Code becomes more brittle but will be less HTML. What is the common way to solve problem like this?
 
Back
Top