Displaying all information across the page width is a feature that

My gridview has 13 columns, all bound fields. When data is bound to the gridview, it causes the page to stretch and the layout becomes lackluster. The page where the gridview is located is inherited from a master page and the gridview is within a panel. We use percentages instead of pixels, which is causing this issue. Using pixels to set the width works fine, but not when using percentages. I have attempted the following solutions:

  1. Removing bound fields and using template fields with fixed itemstyle-width.
  2. Putting the gridview inside a table and applying styles for width, overflow, and other properties.
  3. Placing the gridview inside a div and applying styles for width, overflow, and other properties.
  4. Adding the gridview inside a panel and setting properties as mentioned above.

What works: Setting the "tableLayout" property of the gridview to "fixed" keeps it within the range, but the text overlaps, rendering it useless.

Please provide suggestions.

Sample Code:

<table>
            <tr>
                <td>
            <asp:Panel ID="pnlSearchResult" runat="server" Visible="false" Width="97%">
            <div style="overflow:scroll;width:100%;table-layout:fixed">
                <asp:GridView ID="grdSearchResult" runat="server" SkinID="NewGridGS" EmptyDataText="No records found"
                Width="99%">
                    <Columns>                            
                        <asp:BoundField DataField="ECode" HeaderText="Code"/>
                        <asp:BoundField DataField="EName" HeaderText="Name" />
                        <asp:BoundField DataField="Type" HeaderText="V Type" />
                        <asp:BoundField DataField="VName" HeaderText="V Name" />
                        <asp:BoundField DataField="PStartDate" HeaderText="P Start Date" />
                        <asp:BoundField DataField="PEndDate" HeaderText="P End Date" />
                        <asp:BoundField DataField="VStartDate" HeaderText="V Start Date" />
                        <asp:BoundField DataField="VEndDate" HeaderText="V End Date" />
                        <asp:BoundField DataField="OnSite" HeaderText="On Site" />
                        <asp:BoundField DataField="PCode" HeaderText="P Code" />
                        <asp:BoundField DataField="PSCode" HeaderText="PS Code" />
                        <asp:BoundField DataField="AmountUSD" HeaderText="Amount (USD)" />
                        <asp:BoundField DataField="AmountINR" HeaderText="Amount (INR)" />
                    </Columns>
                </asp:GridView>
                </div>
            </asp:Panel>
        </td>
        </tr>
        </table>

Answer №1

Instead of using a percentage for the width of the div that contains the grid, specify it in pixels

<td>
<div id="divGrid" style='position:absolute; width:800px; overflow:auto'>

<!-- your grid here -->

</div>

</td>

To determine the width of the screen in pixels and convert it into a percentage, you can calculate it accordingly. For example, if the width of the screen is 1000 pixels, then 90% would be equivalent to 900px.

<script language="javascript" type="text/javascript">
   document.getElementById('divGrid').style.width = screen.width + "px";
</script>

Answer №2

Feel free to utilize 100% as your desired percentage without the need for Javascript

<td>
    <div id="gridDiv" style='width:100%; overflow:auto;'>
        <!-- insert your grid content here -->
    </div>
</td>

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

Is it possible to update the content page without having to refresh the master page?

Our website features a Master page with main menu options and corresponding sub menus. When a user clicks on a main menu item, the relevant sub menus should be displayed. After clicking on a sub menu, the content page should update without having to refr ...

text shaped into a curve within a container

$().ready(function() { $('#demo1').circleType({fitText:true, radius: 180}); }); $().ready(function() { $('#example').arctext({radius: 250}); }); <script type="text/javascript" src="http://ajax.googleapis.com/ ...

Create XML and HTML reports using the NUnit GUI

In our automation project, we have opted to utilize the Nunit unit testing framework. For executing the test cases locally, we are relying on NUnit GUI. Additionally, a web application has been developed using the NUnit Core dll to allow multiple us ...

Proper method for integrating Web Api into an existing .net Web Application project

I am looking to transform my current website into a Single Page Application (SPA) with REST support through WebApi 2. Rather than integrating the services directly into my existing project, I prefer to enable JavaScript requests to access my Web API layer. ...

Ways to add a CSS class to an ID that immediately follows

I've been working on an editable table using the HTML5 attribute contenteditable. Everything was going smoothly until I had an idea to highlight the cell that was just updated by adding a class called alert-danger from Bootstrap. Once a cell is succe ...

Tips for keeping several buttons in the spotlight: HTML/CSS/JS

Looking for a solution to keep multiple buttons toggled on? I'm not very familiar with JavaScript, but I know that adding a class on click won't work if there's already a class set. Maybe giving the element an ID could be a possible solution ...

Continuous loop of images displayed in a slideshow (HTML/JavaScript)

Greetings everyone, I am currently working on creating an endless loop slideshow of images for my website. Despite researching several resources, I am still struggling to get the code right. The issue I am facing is that only the image set in the HTML code ...

What is the best way to clear and fill a div without causing it to resize?

I am faced with a challenge involving four thumbnail divs labeled .jobs within a #job-wrap container. When a .job is clicked, I want the #job-wrap to fade out, clear its contents, load information from the selected .job, and then fade back in. However, whe ...

Is it possible to customize the default styling options in Tailwind?

I am currently working on a blog using NextJS, and I have encountered an issue with Tailwind's list style type. It seems that the default styling for list style type is set to list-none, resulting in my <ul> <li> elements not being styled ...

Problem with personalized Domino login page

I have been working on creating a custom login page in domcfg.nsf. Everything is functioning as expected, except for the Style Sheets. I am attempting to load them from the same Domino server, but it appears they are unable to load until I actually log in ...

Securing SOAP communications by encrypting messages sent through HttpWebRequest and treating the SOAP message as a string

After successfully implementing a SOAP client following the code provided in this thread Client to send SOAP request and received response, I am now looking to enhance it by enabling encryption of the soap message using X509 certificates and tripleDes. I a ...

Ways to evenly space out the elements in my Bootstrap 4 navbar

I am struggling to evenly space my elements in the navbar. I have tried various solutions from other sources but haven't found anything that works for me. <nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <div cla ...

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" ...

Steps to establish the starting value as 'Concealed'

I stumbled upon this interesting example that demonstrates how to create expandable/collapsible text when clicked. My question is, how can I initially set the value to be hidden so that the paragraph starts off collapsed and expands only when clicked? He ...

unreachable because of its security settings

In my listview, I am displaying the value of version (WrmVersion), but with a condition. If WrmVersion is null, then display 'None' (ResourcePolicyAvailSystemsLVI.m_nullString="None"). However, I am encountering an error. 'Ship.Controls.R ...

Stacking background images in CSS above other contained elements in a div

I've been experimenting with adjusting the z-index of elements in my code but haven't had any luck. Is it even possible to achieve what I want? Within a div element, I have set a background image using CSS. Inside this div, there are other eleme ...

AngularJs - Customizable dynamic tabs that automatically adapt

Below is the HTML code snippet: <div> <ul data-ng-repeat ="tab in tabs"> <li data-ng-class="{active: tab.selected == 'true'}" message-key="Tab"> </li> </ul> </div> As shown ...

What are some tips for incorporating Fonts in PDFsharp on my Website?

While working on an Azure WebApplication website, I encountered an issue with the Arial font. Specifically, when I reached the line: MainFont = new XFont("Arial", FontSize); An exception was thrown stating: Font data could not be retrieved. I assumed th ...

Tips for including a class in a HTML document using jQuery?

I have successfully included my header and footer in separate HTML files using jQuery's .load() function. The jQuery code I used is shown below: $(function(){ $("#header").load("page-component/header.html"); $("#footer").load("page-component/f ...

Tips for customizing the appearance of an HTML dropdown menu

Here is the code snippet: <select name="xyz" id="abc"> <option value="x">10/Page</option> <option value="y">20/Page</option> <option value="z">30/Pa ...