how to remove and add css class to a specific textbox inside gridview in c# asp.net?


Tags: c#,html,asp.net,css,gridview

Problem :

Please tell me how to remove and add CssClass to a specific textbox inside gridview ?

This is what i have tried but it doesnot changee css for the textbox

my css in my .aspx page is :

<style type="text/css">
   .erroramount
   {
       border:3px solid red
   }
</style>

in my button click here is my code for gridview looping where depending upon the condition i want to change the border color of the textbox;

 var result = (from f in dtCloned.AsEnumerable()
                      group f by f.Field<string>("AssetDescription") into g
                      select
                      new
                      {
                          AssetDescription = g.Key,
                          TotalAmount = g.Sum(r => r.Field<double?>("Amount"))
                      });

foreach (var aAsset in result.AsEnumerable())
{
  if (aAsset.TotalAmount < 0)
  {
     foreach (GridViewRow arow in GridProjectDetails.Rows)
     {
         string AssetDescription = ((TextBox)arow.FindControl("TextAssetDescription")).Text;
         if (AssetDescription == aAsset.AssetDescription)
         {
             ((TextBox)arow.FindControl("TextAmount")).CssClass = "erroramount";
         }
     }
   }
 }


Solution :

Your statement should work unless the code is not reachable or its not finding the control. It would have thrown exception if control was not found.There is an alternate way to set the class as well:

((TextBox)arow.FindControl("TextAmount")).Attributes["class"] = "erroramount";

    CSS Howto..

    Selenium: How to get text from within an html tag which has another tag in it

    How to make three DIV align vertical if not enough space horizontal

    Style elements based on how many elements there are using just CSS?

    How to correctly apply a CSS style to all the images in a div having a specific class?

    How can I use jQuery to add a fade in hover effect to my nav items?

    How to use YUI Compressor in Ant build script for javascript and css

    How to Position an Element Absolute from Center - CSS

    How to create a DIV style switcher in JavaScript?

    how to change :nth element background size

    Scroll Bar not Fully show the value In Div

    How to Automatically Close Alerts using Twitter Bootstrap

    how to grow height with the amount of text in css?

    How to manage assets for modern/ancient browsers

    How do I make a placeholder for a 'select' box?

    How to make the height REALLY 100%

    How do I apply an image to background using inline CSS?

    How can I make CSS affect DOM elements generated after the CSS was interpreted?

    How to get Style From jQuery in angular2

    CSS Sprites - How to align and make responsive?

    How to change label using CSS?

    how to choose what transform is applied first in css

    Website elements go haywire when the user zooms in or out. How do I keep them from moving?

    How to load local copy of bootstrap css when the cdn server is down?

    How to not inherit CSS styles from parents? [duplicate]

    How to keep active menu item underlined?

    When I try to print a page I created using jQuery Mobile, it always prints an extra blank page. How can I stop this?

    How to move full size image slider horizontally using jquery

    How to asynchronously load CSS using jQuery?

    How to define the width of a HTML element dynamically

    How to keep symmetry with CSS fluid spacing of dynamic content