Hi ,
I have a Questionnaire form in my application, which i am developing using C# & ASP.NET. The form should have a fixed number of main questions (8) and each main Question has a number of sub questions (say 6). I created a repeater to accomplish this. SOme Main questions may have only 2 sub questions.. others may have 6 sub questions..
The form displays and print nice on IE but on MAC, the empty rows are visible and the print out doesnt look good with all the empty rows. What can I do to get rid of these empty spaces on Mac?
Thanks in advance

Dani AI

Generated

Nice catch by — this is a browser/UA-stylesheet printing quirk (Safari/WebKit) rather than a Mac OS vs Windows issue. confirmed a CSS-based approach fixed the immediate problem. Below are a few brief, durable options and why they matter years down the road.

Why it happens: your Repeater outputs table rows and cells even when there are no subquestions. Some browsers will still draw cell borders/height when printing if the cell contains any node (including whitespace or a non‑breaking space), or because the user-agent stylesheet forces table cell rendering. The most robust fix is to avoid emitting empty markup in the first place — remove or hide rows that have no real content so no browser needs to decide how to render them.

Server-side (most reliable): suppress empty rows when binding the Repeater. Example pattern in ItemDataBound — check the subquestion count and hide the item/row if zero.

protected void rptMain_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
        return;

    var row = (DataRowView)e.Item.DataItem;
    int subCount = Convert.ToInt32(row["SubCount"]);
    if (subCount == 0)
        e.Item.Visible = false; // removes the markup entirely
}

Client-side / print fallback: if server changes are harder, use a print stylesheet or a beforeprint script to hide rows that contain only whitespace. Note that CSS selectors like :empty will not match cells that contain  , so a small script that checks textContent.trim() is safer.

window.addEventListener('beforeprint', function () {
  document.querySelectorAll('table tr').forEach(function (tr) {
    var allEmpty = Array.from(tr.cells).every(function (td) {
      return td.textContent.trim() === '';
    });
    if (allEmpty) tr.style.display = 'none';
  });
});

See the spec/support details for the related CSS features at MDN: empty-cells, :empty, and .

Recommended Answers

All 2 Replies

its not about the mac, its about the browser, safari i assume

try to set this on the table style and see if it corrects it

empty-cells:hide;

that worked like acharm. thank you so much.. i really appreciate it. i had been experimenting with this since morning.. thank you so much..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.