How to use CSS to conceal asp:BoundField elements

Can someone help me figure out how to hide my asp:BoundField using CSS without losing access to the values? I've tried setting visible=false, but that prevents me from accessing the values. Then I attempted to hide it with CSS, but that doesn't work because CSS is not allowed in BoundFields. I also tried using an UpdatePanel or a div, but those options are not allowed either. Any suggestions on how I can successfully hide my BoundField with CSS?

Here is the code snippet of what I want to hide with CSS:


<asp:BoundField DataField = "compras_id" HeaderText="Compras ID" HtmlEncode="false" />
<asp:BoundField DataField = "numero_contrato" HeaderText = "Numero contrato" HtmlEncode="false" />
... (additional BoundField elements)

This is the CSS I'm currently using:

.myHide {
    display:none;
}

And here's why I need to hide the BoundFields - this is my front-end code snippet:

<asp:GridView> 
    ... (more GridView layout details)
    <Columns>
        <!-- Code section where BoundFields are included -->
    </Columns>
</asp:GridView>

For reference, this is part of my backend logic:

private void GetSelectedRows() {
    // Logic for selecting rows
}

// Additional backend methods and functions...

To summarize, I am trying to find a way to hide certain BoundFields in my ASP.NET application using CSS without losing access to the data they contain.

Answer №1

It's more advisable to utilize a templatefield instead of a boundfield.

Keep in mind that setting visibility to false on webcontrols means they won't be included in the response.

<asp:templatefield>
   <itemtemplate>
      <span class='hidden-element'><%# eval("columnname") %></span>
   </itemtemplate>
</asp:templatefield>

Furthermore, using a repeater offers better control over the generated HTML, which might lead to more suitable outcomes for your requirements.

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

Tips on setting a background image to a div element

I'm facing an issue with a div setup like this: https://i.sstatic.net/4nuyO.png My goal is to remove a specific section of the circle shape displayed below: https://i.sstatic.net/09IWX.png The desired outcome is to achieve a final shape similar to ...

Issues with the z-index in a dropdown menu

Hey, need a little assistance here. I'm facing an issue with my drop down menu. It seems to always be one layer behind the body, even though I've set the z-index of the menu to 999 and the z-index of the body to -999. Could you please take a loo ...

Creating smooth transitions with CSS in React by fading text in when a user clicks a button

Within this presentational component: const HowToControls = props => { return ( <div className="col-md-6 how-to"> {props.isOpen ? <p className={`text ${props.isOpen ? 'visible' : ''}`}> lorem ...

In TypeScript version 2.4.1, the fontWeight property encounters an error where a value of type 'number' cannot be assigned to the types of '"inherit", 400'

When attempting to set the fontWeight property in TypeScript, I encounter the following error: Types of property 'test' are incompatible. Type '{ fontWeight: number; }' is not assignable to type 'Partial<CSSProperties>&a ...

JSON format is used for returning values from WebMethod calls

How can I retrieve values from a Webmethod and format them in JSON for the client? I have two static int values that need to be returned. Do I have to create a new object with these properties each time, or is there a more efficient way to handle this? Th ...

Is there a way to use Media Queries to require CSS to load an image?

Here is the CSS code I am using: html { background: url(../img/header_mobile.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; } /* Smal ...

Arranging Web Application Design at the Component Level using Visual Studio 2010

Seeking guidance on arranging components in a C# web application within Visual Studio. On the form are multiple text fields with individual labels of varying lengths, resulting in alignment challenges. What strategies should be employed for organizing web ...

Guide on creating a JQM website with a stunning image carousel

I've experimented with several image carousels for my mobile sites, but none of them are delivering the results I seek. What I'm looking for is something similar to this site: If you view the above link on a mobile device, you'll notice th ...

Unexpected white space appears at the bottom of the page when rotating the device in iOS Safari

One issue I encountered on my website involves a meta tag: <meta name="viewport" content="width=device-width, initial-scale=1.0"> This, combined with height:100%; on the html and body tags, causes problems when viewed on Safari ...

Getting rid of unwanted scrollbars in a breeze

I am facing an issue with two nested divs that have the same height settings. The outer div has a max-width/height constraint along with overflow auto, causing scrollbars to appear when the inner content exceeds its dimensions. However, even if I resize ...

MaxwidthLG in Material UI design

Hi there, I've encountered an issue with Material UI CSS. Even after attempting to override it, the desired effect is still not achieved. My goal is for the entire div to occupy the full page but this is the current result: https://i.stack.imgur.com/b ...

Is there a way to stop users from signing up with certain usernames?

Currently, I am utilizing the ASP.NET authentication techniques and I have a need to restrict my users from registering with specific usernames. What is the most effective way for me to prevent this issue? I'm curious if there exist any integrated me ...

Creating CSS wrappers around div elements of varying sizes

I am looking for a way to "wrap" different divs of varying sizes, similar to how Microsoft Word wraps text around an image. I have a simplified structure outlined below: <div id = "div1"></div> <div id = "div2"></div> <div id = ...

Update gridview information with a redirect response

The print button in the grid view below opens a print page in a new tab. This is achieved using the following Java Script code: Java Script <script type="text/javascript"> function SetTarget() { document.forms[0].target = "_blank"; ...

When the dropdown form options in HTML are clicked, they appear disproportionately large compared to the initial select box

Sorry if my wording is a bit off, I'm still relatively new to working with CSS and HTML. I've encountered an issue where the dropdown options appear much larger than the select box itself when clicked. I can't seem to figure out how to fix i ...

OnePageCheckout may result in empty boxes being displayed due to OneStepCheckout CSS styling

Seeking advice for an issue with the Magento OneStepCheckout module. Upon checkout, there are three columns: customer data (working fine), payment options (selectable via checkbox), and details about the chosen payment method. Unfortunately, the informati ...

"Utilizing a custom CSS style for a half heart rating system

I am currently working on implementing a rating system using the font-awesome fa-heart class. While I have successfully colored the full heart, I am facing difficulty in filling only the first half of the heart in red. Despite my research efforts, all solu ...

Issue with presenting the scrollbar alongside the Dropdown menu

I'm in the process of creating a menu with multiple items and sub-items. I'd like to have a scroll bar appear alongside the items if they become too numerous. The same goes for sub-menus and so forth. Check out this example to see what I mean. ...

Aligning msform using CSS

Can someone assist me with centering the form (#msform, #msform fieldset) on all browsers while also keeping the image within the border and ensuring that the form does not extend beyond the right border? JSFiddle #msform { width: 1200px; margin: ...

jquery fails to alter label:before

I have encountered a peculiar issue with jQuery and labels. It's quite strange because everything seems to work fine when I change the background color of a label or its font-weight, but using the :before selector doesn't seem to work. Any thoug ...