Click here to Skip to main content
16,007,885 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi...
I am creating manually HTML table from codebind.
Here is my code

ASP.NET
<form id="form1" runat="server">
        <div id="reportGrid" runat="server">

        </div>

    </form>



for (int i = 0; i < rptData.Length; i++)
            {
                headerHtml = headerHtml +
                "<pre><table style='width: 750px' class='rptBody'>" +
                "<tr>" +
                    "<td style='width: 85px; font-weight: bold;'>Remark Posted:</td>" +
                    "<td style='text-align: left; width: 175px'>" + dr["MainRemark"] + "</td>" +
                    "<td style='text-align: right; width: 175px'>Posted On:</td>" +
                    "<td style='text-align: left; width: 175px'>" + dr["PostedOn"] + "</td>" +
                "</tr>" +
            "</table>" +

}
reportGrid.InnerHtml = rptHtml;


my problem is..
all data come in good manner.
but... i want to stop the record to print if the height goes outside the limit.
Table having some fixed height(suppose 1000px).

How i can break the data to print if table height goes more than 1000px and start new table... with remaining data.

Hope you understand my question.
Posted
Comments
Richard Deeming 2-Feb-16 8:15am    
There is no way for code running on the server to know precisely how the browser will render any given HTML.
Sergey Alexandrovich Kryukov 2-Feb-16 11:13am    
Agree. I think the only working alternative is doing it on the client side. I do such things; it perfectly works.
Please see my other comment and Solution 1.
—SA
Sergey Alexandrovich Kryukov 2-Feb-16 10:57am    
You don't really know it before the table is actually rendered. When it is generated on the server side, it's too early to know. But you can obtain the number in JavaScript on the client side and then adjust your already rendered layout (or whatever you want to do).
—SA
F-ES Sitecore 2-Feb-16 11:20am    
You'll have to just pick a number of rows to show per table rather than going on the height. Your elements only have a height when they are shown in a browser, and they are only shown in a browser after your code has finished running.

Also don't generate html like that either, use an asp:Repeater to build your html.

1 solution

Please see the comment to the question, Richard's and mine. You cannot reliably estimate this value. So, you can use the alternative I suggested: use JavaScript in the client side. The function you may need is this: HTMLElement.offsetHeight — Web APIs | MDN[^].

Don't be confused with the name of this function, just use it to determine the actually rendered height of some element. There is a big catch: read the note about "including vertical padding and borders". It can be a big complication, because the code calling this function should better be agnostics of the style used. I usually used the following technique: I applied my calculations to some parent element (such as div) which I styled to have zero borders, padding and margins, specially for this purpose. The rendering gave a required room for the content of this element, which I could measure using this function.

Just in case, this is how you can read all the style metrics for some already rendered styles: Window.getComputedStyle() — Web APIs | MDN[^].

Anyway, this is the technique which really works; and I'm sure that any attempts to do such calculations on the server side would be just hopeless.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900