Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
380
WebGrid, dynamically naming columns
posted
When a column is resized I need to dynamically rename the column header based on the width. When the grid binds, for each column, I have a long string which contains the three different column names. This all must be done in Javascript.

In OnDataBound I am setting the column name to my default text, but once the data binds and the page is served to the user I lose all the custom naming.

One idea I had is to append a row either to the end of the datatable, or append a row to the grid during OnDataBound. This row would be hidden and would contain my custom header text which I could then access from javascript.

Any other ideas? Is there a way to attach custom data to a column during databind?

Thanks, Jake
  • 28464
    posted

     I think this is best achieved using the built-in ClientScript capabilities of ASP.NET. Instead of tricking the column of the grid in order to store the additional information, maybe you can use some of the methods provided by Page.ClientScript.RegisterXXX methods - for example RegisterArrayDeclaration, to send different values for the given key (could be the field Key of the column).

    Later, you can use javascript to access the information from the array and associate a given key with its respective values.