change backgroundColor in clientside

2 replies. Last post: November 8, 2010 1:55 AM by Martin Lie
Tags :
  • (None)
Johnny LeyvaMember

good day. A questions how change the backgroundColor of the webgrid in clientside

i do function in javascript

function webfgrid_onafteradd()

{

var wgDetalle = ISGetObject("wgDetalle");

 wgDetalle.GetElement.style.backgroundColor = "RED";

 wgDetalle.GetActiveEditCell().element.style.fontWeight = "BOLD";

}

 

in serverside use this code

Protected Sub wgDetalle_AddRow(ByVal sender As Object, ByVal e As ISNet.WebUI.WebGrid.RowEventArgs) Handles wgDetalle.AddRow

Sub wgDetalle_AddRow(ByVal sender As Object, ByVal e As ISNet.WebUI.WebGrid.RowEventArgs) Handles wgDetalle.AddRow If Convert.ToDecimal(txtMontoDistribuible.Text) = Convert.ToDecimal(txtTotalDistribuido.Text) Then

   wgDetalle.BackColor = Drawing.Color.Red  Else    wgDetalle.BackColor = Drawing.Color.Blue

   wgDetalle.ClientAction.RefreshAll

 End If End Sub

 

 

but not result

Answers

Martin LieSupport

Hello,

To change background color via Server-side, you can use OnInitializeRow Server-side event such as following:

protected void WebGrid1_InitializeRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e)
{
   e.Row.Style.BackColor = System.Drawing.Color.Red;
}

To change background color via Client-side, you might want to refer to javascript code given by Frank Bruce. The code has been successfully tested and it will change the text color in your WebGrid.

Thank you.

All Replies

Do you want this ?:
Js Code:

    <script type="text/javascript">
        function setForColor() {

            var grid = ISGetObject("WebGrid1");

            for (var i = 0; i < grid.TotalRows; i++) {

                var row = grid.RootTable.GetRow(i);
                var rowElement = row.GetElement();
                rowElement.style.color = "red";
           
            }      
   
        }
    </script>

C# code:

//Set webgrid BackColor 
      protected void Button1_Click(object sender, EventArgs e)
    {
        WebGrid1.LayoutSettings.AlternatingColors = false;
        WebGrid1.RootTable.RowStyle.BackColor = Color.Red;
    }

Martin LieSupport

Hello,

To change background color via Server-side, you can use OnInitializeRow Server-side event such as following:

protected void WebGrid1_InitializeRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e)
{
   e.Row.Style.BackColor = System.Drawing.Color.Red;
}

To change background color via Client-side, you might want to refer to javascript code given by Frank Bruce. The code has been successfully tested and it will change the text color in your WebGrid.

Thank you.

All times are GMT -5. The time now is 6:06 AM.
Previous Next