When an abundance of columns are present, the Asp.net gridview spills out of its containing div

Struggling to contain a gridview within a div with relative widths? It always seems to overflow its parent container when there are too many columns.

A fixed width can help, but resizing the window causes the gridview to overflow once again due to its specific width.

<div style="overflow: scroll; width: 1000px; Height: 300px;">
   <asp:GridView id="GridView1" runat="server"  />
</div>

Is it possible to specify a relative width for the container and still use overflow:scroll so that the gridview resizes along with its container when the window size changes?

Encountering issues while using width:100%. Oddly enough, the gridview overflows at 100% zoom but not at lower zoom levels. Quite perplexing!

Any assistance offered would be greatly appreciated.

100% Zoom:

https://i.sstatic.net/E2jON.png

75% Zoom:

https://i.sstatic.net/QsHSm.png

65% Zoom:

https://i.sstatic.net/J3Nu6.png

Answer №1

One solution to consider is using the CSS property overflow-x: auto.

<div style="overflow-x: auto; width: 1000px; Height: 300px;">
   <asp:GridView id="GridView1" runat="server"  />
</div>

Upon reviewing your screenshots, it appears that not just the grid but also the form div and some other divs above the form are overflowing. In this scenario, adjusting the overflow-x property of the parent div may be necessary.

Answer №2

After countless attempts to find a CSS solution, I decided to turn to jQuery for help:

<script type="text/javascript>

        $(document).ready(function () {
            bindEvents();
        });
        function bindEvents() {
            $(window).on('resize', function () {
                adjustNewSize();
            });
        }
        function adjustNewSize() {

            var parentContainer = $("#divParentContainer");
            var gridContainer = $("#divGridContainer");           
            $(parentContainer).width("80%");        
            $(gridContainer).width(($(parentContainer).width()));

        }       

    </script>

Additionally, below the Toolkit:ToolkitScriptManager, I added the following script:

<Toolkit:ToolkitScriptManager ID="YourToolKitID" runat="server">
    </Toolkit:ToolkitScriptManager>
    <script type="text/javascript>
        var prm = Sys.WebForms.PageRequestManager.getInstance();

        // Event listener for end request
        prm.add_endRequest(function () {
            bindEvents();
        });
    </script>

This setup worked perfectly on Internet Explorer, Mozilla, and Chrome. However, I noticed that the minimize/maximize buttons of the browser sometimes did not trigger the resize event as expected. It seemed like the event was firing, but the divs were not adjusting automatically as they should when manually resizing the browser window.

Answer №3

Perhaps consider using a percentage for the width instead of pixels... For example: width: 90% Using a pixel value sets a fixed size, whereas using a percentage adjusts the width based on the container size

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Present the contents of directories and files stored on a remote desktop computer through a website interface

I've been working on creating a website that can display the folders and files from a remote computer. I've explored options like RDP and RDC, but they require a remote desktop application to access. Currently, I am using asp.net, C#, and JavaScr ...

Is it possible to make a div resize to fit its container?

I have a square block measuring 100*100px. The container block it is within can be resized. I need the inner block to adjust its size dynamically so that it always fits inside the parent container without overflow and maintains its square shape. Important ...

Display sourcemaps on Chrome's network panel

Recently, I began utilizing source maps for my SASS code in order to debug more efficiently in Chrome. My understanding was that Chrome should request both the stylesheet resource and the .map resource, however, only the stylesheet is visible in the netwo ...

I encounter issues when editing a GridView where both the data keys and new values are null

I am working with an ASPX code for a grid view that looks like this: ASPX: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AutoGenerateEditButton="True" BackColor="White" BorderColor="#CC9966" ...

The border in my HTML table is not displaying when I run my flask application

My flask application was running smoothly in a virtual environment until I encountered an issue with the html borders not showing up. Even after seeking help from a friend who knows some html, the problem still persists. app.py: from flask import Flask, r ...

Customizing the font color and size of the brand text in the Bootstrap 5.1.3 Navigation Bar is not allowed

I am currently working on a main page that includes a bootstrap navigation bar with a dropdown menu. I have successfully managed to display the dropdown menu and change its color using CSS. However, I encountered an issue when attempting to modify the font ...

Excessive white space is appearing below the title of my card when using Bootstrap 4

As a beginner in PHP and Bootstrap, I encountered an issue with my login form. Everything was working fine until I added <link rel="stylesheet" type="text/css" href="styles.css"> to my header. I cannot simply remove these links from my header as I w ...

Changing the appearance of the navigation bar

<!-- Bootstrap 5.0.x library --> <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3c5e5353484f484e5d4c7c09120c120e">[email protected]</a>/dist/css/bootstrap.min.css" ...

Using JavaScript to Toggle Visibility of Div Elements

Hi there! I'm having some trouble with a code that is supposed to show/hide div content based on the selection from a jump menu. Unfortunately, it's not working as expected. Here is the snippet of my code: JS: function toggleOther(chosen){ if ( ...

Elevate your experience by switching to FontAwesome Pro within ASP.NET Zero (Angular) - Say goodbye to square icons for good

Recently, I received a task to upgrade a project built with ASP.NET Zero to include Font Awesome Pro icons. Following the guidelines provided here for Installing the Pro version of Font Awesome After including the following line in the angular.json "nod ...

Removing the dividing line between columns in an Antd table: A simple step-by-step guide

Do you notice the lines dividing each table column heading in the image? I want to get rid of these lines from the table. The table component I am using is Antd table. https://ant.design/components/table#examples https://i.stack.imgur.com/Npx5G.png ...

Issue: Stylesheet not being loaded on Index.html through Gulp

Issue The .css file is not being loaded by the index.html despite setting up a gulp.js file. It seems like the folder directory might be causing the problem. However, the .scss files in the /src/scss folder are compiling correctly into CSS within the /bui ...

Ways to pinpoint and customize individual components with CSS

As someone who is not very experienced with HTML and CSS, I have a question... I am unsure of the correct terminology, but in the example below, how can I apply CSS to style ONLY the paragraph tags within each element? For instance, how would I write CSS ...

The name 'Landbot' cannot be located. Have you meant to type '_landbot' instead?

I'm currently in the process of integrating Landbot into my React.js application with TypeScript. I'm following this [doc] 1. However, I'm facing an issue where the code inside useEffect (new Landbot.Container) is causing an error. 'C ...

Is there a way to disable certain CSS features in Chrome, like CSS grid, for testing purposes?

I'm exploring alternative layouts for my app in case CSS grid is not supported. Is there a way to disable features like CSS grid in Chrome or Canary? ...

What is the best way to create a scrollable Material UI modal and dialog?

Having a problem with my mui modal where the top content is getting cut off and I can't scroll up. I've tried adding the {overflow:"scroll"} property to the modal but it's not working. Here's the code snippet I'm currentl ...

Text remains unaltered on input focus

When I click on the input field, I expect the label to transform but it doesn't. However, using ".user-input:focus, .user-input:valid" changes the input, indicating that it should work with the label as well. .user-input:focus+.user-label, .user-in ...

Interruption of client-side JavaScript by the ASP timer tick event

Exploring the Situation In the realm of web development, I find myself immersed in creating a web application dedicated to monitoring various services. Each service is equipped with an UpdatePanel, showcasing status updates along with interactive buttons ...

SQL query - establishing a connection between two database tables

I am currently working with two tables in my Access database. The first table is called Messages and it contains the following fields: MessageID MessageFrom MessageTO MessageSubject Messages The second table is named User and it consists of these fields ...

What is the reason behind line-height not affecting the clickable area when reduced?

I have been working on a personal project where I added thumbnails for images that can be scrolled through and clicked to set the main image. However, I encountered a strange issue. To demonstrate the problem, I created a Stackblitz project here: https:// ...