Asp.net custom grid vs GridView / ListView

A few years ago I decided to create my own DataGrid as I didn't like the standard one provided by Microsoft. Its a very simple function that takes a DataTable as an input and returns a string (html code to display the table on a web page).

Its very flexible (there are some optional parameters to do the search, sort and format each column the way I want) and fast (only the records that are in use are fetched from the database). The function itself is very short (about 20 lines of code). I have used it for at least 4 years.

Assuming you have a PlaceHolder in your webpage, this is how you can call a custom function:

MyPlaceHolder.Controls.Add(new LiteralControl(CreateCustomGrid(MyDataTable)))

      

CreateCustomGrid (MyDataTable))) will return something like this (assuming MyDataTable has 2 columns and 2 rows):

<table class="MyClass"  rules="all">
  <tr>
      <th>Column1</th>
      <th>Column2</th>
  </tr>
   <tr>
      <td align="center">Value1</td>
      <td align="center">Value2</td>
  </tr>
    <tr>
      <td align="center">Value3</td>
      <td align="center"><a href=’MyLink’>Value4</a></td>
  </tr>
  </table>

      

Internally, the function knows how to format each column (this function is only used on one website), but it is also possible to change it for each individual column with additional options. Ditto for paging and sorting. Everything is very flexible and very easy to use.

Now everything has changed and the DataGrid has been replaced by the GridView and / or ListView. I've looked at them, but I can't see anything they do that my function does not, so I would be tempted to continue using my function, but I might be ignoring something. At the same time, it's a bit weird to keep using a custom function to generate the html table. What are your views on this?

+1


source to share


2 answers


If your code works and is hardened, I would not change any existing code. For additional functionality, you might consider migrating it to a custom data-bound WebControl. This way you can use data sources etc.



+1


source


I would say that you should research the GridView / ListView to see what they can do, but ultimately if you and your customers are happy with their own code and it works for you, does whatever you need to needs to be changed because there is something else there.



0


source







All Articles