views:

777

answers:

1

So i had a feature request to add fields to a second table row for a single data row on a GridView. At first, I looked at extending the functionality of the GridView but soon realized this would be a huge task and since I consider this request a shim for a larger future feature decided against it. Also want to move to MVC in the near future and this would be throw away code.

So instead I created a little jquery script to move the cell to the next row in the table.

$(document).ready(function() {
 $(".fieldAttributesNextRow").each(function() {
  var parent = $(this).parent();
  var newRow = $("<tr></tr>");
  newRow.attr("class", $(parent).attr("class"));

  var headerRow = $(parent).parent().find(":first");
  var cellCount = headerRow.children().length - headerRow.children().find(".hide").length;

  newRow.append($(this).attr("colspan", cellCount));
  $(parent).after(newRow);
 })
});

What do you think of this? Is this a poor design decision? I am actually quite pleased with the ease of this solution. Please provide your thoughts.

A: 

This is client side code, as long as users are not going to play with the gridview after it is loaded, it should be fine. However, if you want to do anything with postbacks, this might need some refactoring.

What are you trying to achieve with the gridview? Remmber that you can hook into the Row bind event and modify the current row however you need to.

BenB
What do you mean "play with the grid"? This script takes cells marked with the "fieldAttributesNextRow" class and moves them to a newly created row under their existing row. It is purely a layout issue.I am using postbacks to edit/save inline on the grid everything works great.
chief7