iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Hi all,
I have a aspx page that calculate the prices of the product with a column NetAmountNetAmount.
I need to color in red this column only in some conditions are true.
I try to insert some code
row.Cells.GetNamedItem("NetAmount").Row.Style.ForeColor = "Red";
row.GetCells().GetNamedItem('NetAmountNetAmount').GetElement().style.color = "Red";
but i have these error when try to set the color
row.Cells.GetNamedItem("NetAmount").GetElement() is NULL
this is the function that i call in the code
function WebGridPrices_OnInitializeRow(controlId, row) { //userdefined/edit.aspx?id={380C9D74-F738-DF11-B28F-005056B50AB3}&etc=10011# var orgname = getQuerystring('orgname', ''); if (orgname != '') { orgname = '/' + orgname; } if (row.Cells.GetNamedItem("discountScaleName") != null) { row.Cells.GetNamedItem("discountScaleName").Value = [window.location.protocol, '//', window.location.host, orgname, '/userdefined/edit.aspx?id={', row.Cells.GetNamedItem("discountScaleId").Value, '}&etc=', etc, '#'].join(''); } else { if (row.Cells.GetNamedItem("discountScaleName")) row.Cells.GetNamedItem("discountScaleName").Value = " "; } if (row.Cells.GetNamedItem("price")) row.Cells.GetNamedItem("price").Value = convertNumberWithRightFormat(parseFloat(row.Cells.GetNamedItem("price").Value)); if (row.Cells.GetNamedItem("priceType")) { var txt = row.Cells.GetNamedItem("priceType").Value; if (txt.indexOf('rabatt') == -1) { if (row.Cells.GetNamedItem("NetAmount")) row.Cells.GetNamedItem("NetAmount").Value = convertNumberWithRightFormat(parseFloat(row.Cells.GetNamedItem("NetAmount").Value)); } else { var quantity = row.Cells.GetNamedItem("minQty").Value; var priceUnit = row.Cells.GetNamedItem("priceUnit").Value; var discount = row.Cells.GetNamedItem("fixDiscount1").Value; var price = parseFloat(convertTextToNumber(row.Cells.GetNamedItem("price").Value)); var netAmount = parseFloat((quantity / (priceUnit * 100)) * (100 * price - discount * price)); row.Cells.GetNamedItem("NetAmount").Value = convertNumberWithRightFormat(netAmount);
row.Cells.GetNamedItem("NetAmount").CellStyle.ForeColor = "Red"; } } }
The code is
<%@ Page Language="C#" AutoEventWireup="true" EnableSessionState="true" CodeBehind="PriceInfo.aspx.cs" Inherits="Wuerth.Phoenix.Speedy.OrderlineGrid.PriceInfo" %> <%@ Register Assembly="ISNet.WebUI.WebInput" Namespace="ISNet.WebUI.WebControls" TagPrefix="ISWebInput" %> <%@ Register Assembly="ISNet.WebUI.WebCombo" Namespace="ISNet.WebUI.WebCombo" TagPrefix="ISWebCombo" %> <%@ Register Assembly="ISNet.WebUI.WebGrid" Namespace="ISNet.WebUI.WebGrid" TagPrefix="ISWebGrid" %> <%@ Register Assembly="ISNet.WebUI.ISDataSource, Version=1.0.1500.1, Culture=neutral, PublicKeyToken=c4184ef0d326354b" Namespace="ISNet.WebUI.DataSource" TagPrefix="ISDataSource" %> <%@ Register Assembly="ISNet.WebUI.WebDesktop" Namespace="ISNet.WebUI.WebDesktop" TagPrefix="ISWebDesktop" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <html > <head id="Head1" runat="server"> <title></title> <link href="Styles/IFrame.css" rel="Stylesheet" type="text/css" /> <script type="text/javascript"> var productListHash = new ActiveXObject("Scripting.Dictionary"); var firstLoad = true; function TextBoxProduct_onkeypress(event) { if (event.type == "keypress" && event.srcElement.id == "TextBoxProduct" && event.keyCode == 13) { searchPrices_Clicked(); } } function TextBoxProduct_onkeydown(event) { if (isEditProductCustomized == 'true') { if (!(event.ctrlKey && (event.keyCode == 88 || event.keyCode == 67)) && (event.keyCode != 39) && (event.keyCode != 17)) { if (event.type == "keydown" && event.srcElement.id == "TextBoxProduct") { var newTextBoxValue = TextBoxProductFormatProductNumber.formatProductString(event.keyCode); if (newTextBoxValue != null) { event.srcElement.value = newTextBoxValue; if (newTextBoxValue.length == 0) { event.srcElement.select(); } event.returnValue = event.keyCode == 13 /*enter*/ || event.keyCode == 9 /*tab*/; } } } } } function body_onload(event) { var TextBoxProduct = document.getElementById("TextBoxProduct"); TextBoxProductSelection = new WuerthPhoenix.Utility.Selection(TextBoxProduct); TextBoxProductFormatProductNumber = new WuerthPhoenix.Utility.FormatProductNumber(TextBoxProduct, productFormat); TextBoxProduct.attachEvent('onkeydown', TextBoxProduct_onkeydown); TextBoxProduct.onkeypress = function() { TextBoxProduct_onkeypress(event); }; TextBoxProduct.focus(); } function searchPrices_Clicked() { var grid = ISGetObject("WebGridPrices"); grid.Refresh(); } function PriceInfoItem() { this.productNumber = ""; this.productName = ""; this.priceIdentifier = ""; this.priceIdType = ""; this.priceName = ""; this.price = ""; this.minQty = ""; this.priceType = ""; this.manualPrice = ""; this.manualDiscount1 = ""; this.manualDiscount2 = ""; this.manualDiscountAmount = ""; this.fixDiscount1 = ""; this.fixDiscount2 = ""; this.fixDiscountAmount = ""; this.fixCommission = ""; this.discountScaleType = ""; this.discountScaleName = ""; this.priceUnit = ""; this.priceUnitId = ""; this.maxDiscount = ""; this.minDiscount = ""; this.maxCommission = ""; this.pricetypeId = ""; this.discountScaleId = ""; this.isGeneralManualPrice = ""; this.hierarchyPriority = ""; this.priceListPriority = ""; this.typePriority = ""; this.prodgroupdes = ""; this.priority = ""; this.authrequired = ""; } function Service_Selecting(control, selectArguments) { var IncomingData = new Object(); IncomingData.UserID = userId; IncomingData.Orgname = getQuerystring("orgname"); IncomingData.UserLCID = getQuerystring("userlcid"); IncomingData.AreaID = '00000000-0000-0000-0000-000000000000'; var currency = ISGetObject("WebComboCurrency"); var account = ISGetObject("WebComboAccount"); var comboArea = ISGetObject('WebComboArea'); IncomingData.CustomerID = '00000000-0000-0000-0000-000000000000'; if (account.Value != null && account.Value != "") { IncomingData.CustomerID = account.Value; } if (accountName != null && accountName != "" && firstLoad) { document.getElementById('txtAccountNumber').innerText = accountName; firstLoad = false; } if (comboArea.Value != null && comboArea.Value != "") { IncomingData.AreaID = comboArea.Value; } IncomingData.CurrencyID = '00000000-0000-0000-0000-000000000000'; if (currency.Value != null && currency.Value != "") { IncomingData.CurrencyID = currency.Value; } var quantity = document.getElementById('TextBoxQuantity'); IncomingData.MinQty = 100000; if (quantity.value != null && quantity.value != '') { IncomingData.MinQty = parseInt(quantity.value, 10); } var TextBoxProduct = document.getElementById('TextBoxProduct') IncomingData.Product = TextBoxProduct.value == "*" ? "" : TextBoxProduct.value; IncomingData.ApplyProductDist = document.getElementById('HiddenApplyProductDist').value; selectArguments.FilterExpression = IncomingData.UserID + "," + IncomingData.AreaID + "," + IncomingData.CustomerID + "," + IncomingData.CurrencyID + "," + IncomingData.Product + "," + IncomingData.UserLCID + "," + IncomingData.MinQty + "," + IncomingData.ApplyProductDist + "," + 500 + "," + getQuerystring("orgname"); // LogEvent("Selecting data. Operation Type: " + selectArguments.OperationType + ", FilterExpression=" + selectArguments.FilterExpression + // ", SortExpression=" + selectArguments.SortExpression); } function IncomingData() { this.__type = "Wuerth.Phoenix.Speedy.OrderlineGrid.IncomingData"; this.UserID = userId; this.Orgname = getQuerystring("orgname"); this.UserLCID = getQuerystring("userlcid"); this.AreaID = '00000000-0000-0000-0000-000000000000'; var currency = ISGetObject("WebComboCurrency"); var account = ISGetObject("WebComboAccount"); var comboArea = ISGetObject('WebComboArea'); this.CustomerID = '00000000-0000-0000-0000-000000000000'; if (account.Value != null && account.Value != "") { this.CustomerID = account.Value; } if (comboArea.Value != null && comboArea.Value != "") { this.AreaID = comboArea.Value; } this.CurrencyID = '00000000-0000-0000-0000-000000000000'; if (currency.Value != null && currency.Value != "") { this.CurrencyID = currency.Value; } var quantity = document.getElementById('TextBoxQuantity'); this.MinQty = 100000; if (quantity.value != null && quantity.value != '') { this.MinQty = parseInt(quantity.value,10); } var TextBoxProduct = document.getElementById('TextBoxProduct') this.Product = TextBoxProduct.value == "*" ? "" : TextBoxProduct.value; this.ApplyProductDist = document.getElementById('HiddenApplyProductDist').value; } //end class function WebComboAccount_OnLostFocus() { var comboAccount = ISGetObject('WebComboAccount'); var accountId = document.getElementById('HiddenAccountId'); if ((comboAccount.Value != accountId.value)|| ((comboAccount.Value != "") && (comboAccount.GetTextBoxValue() == ""))) { if (comboAccount.GetTextBoxValue() == "") { accountId.value = ''; var comboArea = ISGetObject('WebComboArea'); //comboArea.ClearResultBox(); comboArea.ClearSelection(); comboArea.NeedClearList = true; comboArea.SetText(''); comboArea.LoadValue(true); comboArea.NeedClearList = true; comboArea.SetText(areaName); comboArea.SetValue(areaId); comboArea.LoadValue(true); document.getElementById('txtAccountNumber').innerText = ''; document.getElementById('txtFullName').innerText = ''; if (!comboArea.IsValueInRange()) { comboArea.SetText(''); comboArea.SetValue('00000000-0000-0000-0000-000000000000'); } } } } function WebComboAccount_OnAfterItemSelected() { var comboAccount = ISGetObject('WebComboAccount'); var accountId = document.getElementById('HiddenAccountId'); var comboArea = ISGetObject('WebComboArea'); accountId.value = comboAccount.Value; comboArea.ClearResultBox(); comboArea.ClearSelection(); comboArea.NeedClearList = true; comboArea.SetText(''); comboArea.LoadValue(true); comboArea.NeedClearList = true; comboArea.SetText(areaName); comboArea.SetValue(areaId); comboArea.LoadValue(true); if (!comboArea.IsValueInRange()) { comboArea.SetText(''); comboArea.SetValue('00000000-0000-0000-0000-000000000000'); } var rowComboAccount = comboAccount.GetSelectedRow(); document.getElementById('txtAccountNumber').innerText = rowComboAccount.cells[2].innerText; document.getElementById('txtFullName').innerText = rowComboAccount.cells[4].innerText; } function getQuerystring(key, default_) { if (default_ == null) default_ = ""; key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regex = new RegExp("[\\?&]" + key + "=([^&#]*)"); var qs = regex.exec(window.location.href); if (qs == null) return default_; else return qs[1]; } function WebGridPrices_OnInitializeRow(controlId, row) { //userdefined/edit.aspx?id={380C9D74-F738-DF11-B28F-005056B50AB3}&etc=10011# var orgname = getQuerystring('orgname', ''); if (orgname != '') { orgname = '/' + orgname; } if (row.Cells.GetNamedItem("discountScaleName") != null) { row.Cells.GetNamedItem("discountScaleName").Value = [window.location.protocol, '//', window.location.host, orgname, '/userdefined/edit.aspx?id={', row.Cells.GetNamedItem("discountScaleId").Value, '}&etc=', etc, '#'].join(''); } else { if (row.Cells.GetNamedItem("discountScaleName")) row.Cells.GetNamedItem("discountScaleName").Value = " "; } if (row.Cells.GetNamedItem("price")) row.Cells.GetNamedItem("price").Value = convertNumberWithRightFormat(parseFloat(row.Cells.GetNamedItem("price").Value)); if (row.Cells.GetNamedItem("priceType")) { var txt = row.Cells.GetNamedItem("priceType").Value; if (txt.indexOf('rabatt') == -1) { if (row.Cells.GetNamedItem("NetAmount")) row.Cells.GetNamedItem("NetAmount").Value = convertNumberWithRightFormat(parseFloat(row.Cells.GetNamedItem("NetAmount").Value)); } else { var quantity = row.Cells.GetNamedItem("minQty").Value; var priceUnit = row.Cells.GetNamedItem("priceUnit").Value; var discount = row.Cells.GetNamedItem("fixDiscount1").Value; var price = parseFloat(convertTextToNumber(row.Cells.GetNamedItem("price").Value)); var netAmount = parseFloat((quantity / (priceUnit * 100)) * (100 * price - discount * price)); row.Cells.GetNamedItem("NetAmount").Value = convertNumberWithRightFormat(netAmount); // row.Cells.GetNamedItem("NetAmount").CellStyle.ForeColor = "Red"; // <CellStyle ForeColor="Red" /> } } } </script> </head> <body style="width:100%; height: 100%; padding: 0 5 0 5;" onload="body_onload(event);"> <form id="form1" runat="server" style="width:100%; height: 100%;"> <ajaxToolkit:ToolkitScriptManager ID="somename" runat="server" EnablePartialRendering="true" CombineScripts="true"> <Scripts> <asp:ScriptReference Path="script/shortcut.js"/> <asp:ScriptReference Path="script/numberFormat154.js"/> <asp:ScriptReference Path="script/Utility.js"/> </Scripts> </ajaxToolkit:ToolkitScriptManager> <ISDataSource:ISDataSource ID="ISDataSourceAccountInfo" runat="server" SchemaName="Wuerth.Phoenix.Speedy.OrderlineGrid.PriceInfoDataSet"> <Tables> <ISDataSource:ISDataSourceTable DataObjectTypeName="System.Nullable`1[[System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" SelectMethod="GetData" TableName="p_GetAccountInfo" TypeName="Wuerth.Phoenix.Speedy.OrderlineGrid.PriceInfoDataSetTableAdapters.p_GetAccountInfoTableAdapter"> <SelectParameters> <asp:QueryStringParameter Name="userid" QueryStringField="userid" Type="Object" /> </SelectParameters> </ISDataSource:ISDataSourceTable> </Tables> </ISDataSource:ISDataSource> <%-- <ISDataSource:ISDataSource ID="ISDataSourceWebGrid" runat="server" SchemaName="Wuerth.Phoenix.Speedy.OrderlineGrid.PriceInfoDataSet"> <Tables> <ISDataSource:ISDataSourceTable SelectMethod="GetData" TableName="p_GetproductBaseInfo" TypeName="Wuerth.Phoenix.Speedy.OrderlineGrid.PriceInfoDataSetTableAdapters.p_GetproductBaseInfoTableAdapter"> <SelectParameters> <asp:ControlParameter ControlID="TextBoxProduct" Name="prProductNumberOrName" PropertyName="Text" Type="Object" /> <asp:QueryStringParameter QueryStringField="userlcid" Name="prlanguageID" Type="String" /> <asp:ControlParameter ControlID="HiddenUserID" Name="prUserId" PropertyName="Value" Type="Object" /> <asp:ControlParameter ControlID="WebComboArea" Name="prAreaId" DefaultValue="00000000-0000-0000-0000-000000000000" PropertyName="Value" Type="Object" /> <asp:ControlParameter ControlID="HiddenAccountID" Name="prAccountID" PropertyName="Value" Type="Object" /> <asp:ControlParameter ControlID="WebComboCurrency" Name="prCurrencyId" DefaultValue="00000000-0000-0000-0000-000000000000" PropertyName="Value" Type="Object" /> <asp:ControlParameter ControlID="TextBoxQuantity" Name="prMinQty" DefaultValue="100000" PropertyName="Text" Type="Object" /> <asp:ControlParameter ControlID="HiddenApplyProductDist" Name="prApplyProductDist" PropertyName="Value" Type="Object" /> <asp:ControlParameter ControlID="HiddenMaxProduct" Name="prMaxProducts" PropertyName="Value" Type="Object" /> <asp:ControlParameter ControlID="HiddenAlwaysAddCondition" Name="prAlwaysAddCondition" PropertyName="Value" Type="Object" /> </SelectParameters> </ISDataSource:ISDataSourceTable> </Tables> </ISDataSource:ISDataSource>--%> <ISDataSource:ISDataSource ID="ISDataSourceArea" runat="server" SchemaName="Wuerth.Phoenix.Speedy.OrderlineGrid.PriceInfoDataSet"> <Tables> <ISDataSource:ISDataSourceTable SelectMethod="GetData" TableName="p_GetAreas" TypeName="Wuerth.Phoenix.Speedy.OrderlineGrid.PriceInfoDataSetTableAdapters.p_GetAreasTableAdapter"> <SelectParameters> <asp:ControlParameter ControlID="HiddenUserID" Name="prUserId" PropertyName="Value" Type="String" /> </SelectParameters> </ISDataSource:ISDataSourceTable> </Tables> </ISDataSource:ISDataSource> <ISDataSource:ISDataSource ID="ISDataSourceCurrency" runat="server" SchemaName="Wuerth.Phoenix.Speedy.OrderlineGrid.PriceInfoDataSet" CacheDuration="3600" EnableCaching="Yes"> <Tables> <ISDataSource:ISDataSourceTable SelectMethod="GetData" TableName="CurrencyExt" TypeName="Wuerth.Phoenix.Speedy.OrderlineGrid.PriceInfoDataSetTableAdapters.CurrencyExtTableAdapter"> </ISDataSource:ISDataSourceTable> </Tables> </ISDataSource:ISDataSource> <div id="webgrid" class="webgrid" style="height: 100%; width: 100%; overflow-y: auto;"> <table style="width:100%; table-layout: fixed;"> <tr> <td width="7%" style="padding: 0px 5px 0px 5px" valign="middle"> <asp:Label ID="LabelProduct" runat="server" Text="Product"></asp:Label> </td> <td width="26%" style="padding: 0px 5px 0px 5px" valign="middle"> <asp:TextBox ID="TextBoxProduct" runat="server" Width="70%" Font-Names="Tahoma" Font-Size="13px" style="border-bottom-style:solid; border-bottom-width:1px; border-bottom-color:#286a9b; border-top-width:1px; border-top-color:#5794bf; border-top-style:solid; border-left-width:1px; border-left-color:#5794bf; border-left-style:solid; border-right-width:1px; border-right-color:#286a9b; border-right-style:solid;"></asp:TextBox> </td> <td width="7%" style="padding: 0px 5px 0px 5px" valign="middle"> <asp:Label ID="LabelAccount" runat="server" Text="Account" Font-Names="Tahoma"></asp:Label> </td> <td width="26%" style="padding: 0px 5px 0px 5px" valign="middle"> <ISWebCombo:WebCombo ID="WebComboAccount" runat="server" UseDefaultStyle="True" AllowWildCardSearch="True" DataCacheStorage="Session" DataMember="p_GetAccountInfo" DataSourceID="ISDataSourceAccountInfo" DataTextField="accountnumber" DataValueField="accountid" Height="20px" ViewStateStorage="None" Width="30%" AdditionalSearchFields="name"> <Columns> <ISWebCombo:WebComboColumn Width="80" BaseFieldName="accountnumber" Name="accountnumber" HeaderText="Number" /> <ISWebCombo:WebComboColumn BaseFieldName="accountid" Name="accountid" DataType="System.Guid" Hidden="True" RenderOnHidden="true"/> <ISWebCombo:WebComboColumn BaseFieldName="name" HeaderText="Name" Name="name" Width="180" /> <ISWebCombo:WebComboColumn BaseFieldName="transactioncurrencyidname" Hidden="True" Name="transactioncurrencyidname" RenderOnHidden="true"/> <ISWebCombo:WebComboColumn BaseFieldName="FullName" Hidden="True" Name="FullName" RenderOnHidden="true"/> </Columns> <LayoutSettings RoundCorner="False" ComboMode="MultipleColumns"> <ClientSideEvents OnLostFocus="WebComboAccount_OnLostFocus" OnAfterItemSelected="WebComboAccount_OnAfterItemSelected"/> </LayoutSettings> </ISWebCombo:WebCombo> <asp:Label ID="txtAccountNumber" Font-Names="Tahoma" style="padding: 0px 5px 0px 5px" valign="middle" runat="server" Font-Bold="true" Width="75%"></asp:Label> </td> <td width="4%" style="padding: 0px 5px 0px 5px" valign="middle"> <asp:Label ID="LabelPriceAuth" runat="server" Text="User:" Font-Names="Tahoma"></asp:Label> </td> <td width="10%" style="padding: 0px 5px 0px 5px" valign="middle"> <asp:Label ID="txtFullName" Font-Names="Tahoma" style="padding: 0px 5px 0px 5px" valign="middle" runat="server" Font-Bold="true" Width="45%"></asp:Label> </td> <td width="5%" style="padding: 0px 5px 0px 5px" valign="middle"> <asp:Label ID="LabelCurrency" runat="server" Text="Currency" Font-Names="Tahoma"></asp:Label> </td> <td width="14%" style="padding: 0px 5px 0px 5px" valign="middle"> <ISWebCombo:WebCombo ID="WebComboCurrency" runat="server" UseDefaultStyle="True" DataMember="CurrencyExt" DataSourceID="ISDataSourceCurrency" DataTextField="CurrencyName" DataValueField="TransactionCurrencyId" Height="20px" Width="70%" UseCachedDataOnFirstLoad="True"> <LayoutSettings RoundCorner="False" TextBoxMode="ReadOnly" AlwaysShowAllRowsOnDropdown="True" AlwaysShowHelpButton="False"> </LayoutSettings> </ISWebCombo:WebCombo> </td> </tr> <tr> <td width="7%" valign="middle" style="padding: 0px 5px 0px 5px"> <asp:Label ID="LabelQuantity" runat="server" Text="Quantity"></asp:Label> </td> <td width="26%" style="padding: 0px 5px 0px 5px"> <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtenderQuantity" runat="server" TargetControlID="TextBoxQuantity" FilterType="Numbers" /> <asp:TextBox ID="TextBoxQuantity" runat="server" Width="70%" Font-Names="Tahoma" Font-Size="13px" style="border-bottom-style:solid; border-bottom-width:1px; border-bottom-color:#286a9b; border-top-width:1px; border-top-color:#5794bf; border-top-style:solid; border-left-width:1px; border-left-color:#5794bf; border-left-style:solid; border-right-width:1px; border-right-color:#286a9b; border-right-style:solid;"></asp:TextBox> </td> <td width="7%" style="padding: 0px 5px 0px 5px" valign="middle"> <asp:Label ID="LabelArea" runat="server" Text="Area"></asp:Label> </td> <td width="26%" style="padding: 0px 5px 0px 5px" valign="middle"> <ISWebCombo:WebCombo ID="WebComboArea" runat="server" UseDefaultStyle="True" DataSourceID="ISDataSourceArea" Height="20px" Width="70%" DataMember="p_GetAreas" DataTextField="Speedy_name" DataValueField="Speedy_areaId" AllowAutoDataCaching="False" ViewStateStorage="None"> <LayoutSettings RoundCorner="False"> </LayoutSettings> </ISWebCombo:WebCombo> </td> <td width="7%" style="padding: 0px 5px 0px 5px"> </td> <td colspan="3" width="26%" style="padding: 0px 5px 0px 5px" valign="middle"> <table cellpadding="0" cellspacing="0"> <tr> <td> <ISWebDesktop:WebButton style="border: solid 1 black;" ID="ButtonSearch" runat="server" Height="25px" Text="Search" DisplayMode="Text" Width="80px" OnClientClick="searchPrices_Clicked"> </ISWebDesktop:WebButton> </td> <td> <div id="spStatus" style="padding-left: 5; height:20px; vertical-align:middle"></div> </td> </tr> </table> </td> </tr> </table> <ISWebGrid:WebGrid ID="WebGridPrices" runat="server" Width="100%" UseDefaultStyle="True" BindingOperationMode="ClientBinding" DefaultStyleMode="Elegant" StateRestorationLevel="Low" > <LayoutSettings AutoFitColumns="true" AllowColumnMove="Yes" AllowGrouping="Yes" GroupByBoxVisible="True" GroupRowInfoFormatDefault="[caption] : [value] ([count])" AllowContextMenu="True" AllowFilter="Yes" FilterBarVisible="true" AllowSorting="Yes" AlwaysShowHelpButton="False" HideColumnsWhenGrouped="No" ColumnFooters="Yes" AllowExport="No" AutoFilterSuggestion="True" ShowColumnAction="True" ShowRefreshButton="False" AutoHeight="true" PagingMode="VirtualLoad" VirtualPageSize="30"> <ClientSideEvents OnInitializeRow="WebGridPrices_OnInitializeRow" /> <TextSettings Language="UseCustom" /> </LayoutSettings> <RootTable Caption="Prices found" > <%--<GroupedColumns> <ISWebGrid:WebGridGroup ColumnMember="productNumber" GroupInterval="Text" GroupMode="Expanded" SortOrder="Ascending" /> </GroupedColumns>--%> <Columns> <ISWebGrid:WebGridColumn Caption="ProductNumber" DataMember="productNumber" Name="productNumber" Width="100px" TreatMarkupAsLiteralText="True"> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="ProductName" DataMember="productName" name="productName" Width="150px"> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="speedy_prodgroupdes c" DataMember="speedy_prodgroupdes" Name="prodgroupdes" Width="60px" Visible="true"> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Priority" DataMember="priority" Visible="false" name="priority" DataType="System.Decimal" Width="50px"> <CellStyle HorizontalAlign="Right"></CellStyle> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="PriceType" DataMember="priceType" Name="priceType" Width="160px"> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="PriceList" DataMember="priceName" Visible="false" Name="priceName" Width="160px" > </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Aut." DataMember="authrequired" Visible="false" DataType="System.String" Name="authrequired" Width="40px" > </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Quantity" DataMember="minQty" DataType="System.Decimal" Name="minQty" Width="50px" DataFormatString="#" > <CellStyle HorizontalAlign="Right"></CellStyle> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="PricePerUnit" DataMember="price" DataType="System.String" Name="price" Width="50px" DataFormatString="c"> <CellStyle HorizontalAlign="Right"></CellStyle> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Discount 1%" DataMember="fixDiscount1" Name="fixDiscount1" Width="40px"> <CellStyle HorizontalAlign="Right"></CellStyle> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Net Amount" DataMember="NetAmount" DataType="System.String" Name="NetAmount" Width="40px" DataFormatString="c"> <CellStyle HorizontalAlign="Right"></CellStyle> <CellStyle ForeColor="Red" /> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="PriceUnit" DataMember="priceUnit" DataType="System.Decimal" Name="priceUnit" DataFormatString="#" Width="50px" > <CellStyle HorizontalAlign="Right"></CellStyle> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="DiscountScale" DataMember="discountScaleName" Visible="false" Name="discountScaleName" Width="100px" ColumnType="HyperLink" > </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="minDiscount" DataMember="minDiscount" Name="minDiscount" Width="60px"> <CellStyle HorizontalAlign="Right"></CellStyle> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="maxDiscount" DataMember="maxDiscount" Name="maxDiscount" Width="60px"> <CellStyle HorizontalAlign="Right"></CellStyle> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="maxCommission" DataMember="maxCommission" Visible="false" Name="maxCommission" Width="80px"> <CellStyle HorizontalAlign="Right"></CellStyle> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="manualPrice" DataMember="manualPrice" Name="manualPrice" Width="0px" ColumnType="CheckBox" ShowInSelectColumns="No" Visible="false"> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="manualDiscount1" DataMember="manualDiscount1" Name="manualDiscount1" Width="0px" ColumnType="CheckBox" ShowInSelectColumns="No" Visible="false"> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="fixDiscount1" ShowInSelectColumns="No" Visible="false" DataMember="fixDiscount1" Name="fixDiscount1" Width="0px"> <CellStyle HorizontalAlign="Right" ></CellStyle> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="manualDiscount2" DataMember="manualDiscount2" Name="manualDiscount2" Width="0px" ColumnType="CheckBox" ShowInSelectColumns="No" Visible="false"> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="fixDiscount2" ShowInSelectColumns="No" Visible="false" DataMember="fixDiscount2" Name="fixDiscount2" Width="0px"> <CellStyle HorizontalAlign="Right" ></CellStyle> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="manualDiscountAmount" DataMember="manualDiscountAmount" Name="manualDiscountAmount" Width="0px" ColumnType="CheckBox" DataType="System.Boolean" ShowInSelectColumns="No" Visible="false"> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="fixDiscountAmount" DataMember="fixDiscountAmount" Name="fixDiscountAmount" Width="0px" DataFormatString="c" ShowInSelectColumns="No" Visible="false"> <CellStyle HorizontalAlign="Right"></CellStyle> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="fixCommission" DataMember="fixCommission" Name="fixCommission" Width="0px" ShowInSelectColumns="No" Visible="false"> <CellStyle HorizontalAlign="Right"></CellStyle> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="discountScaleId" DataMember="discountScaleId" DataType="System.Guid" Name="discountScaleId" Width="1px" Visible="false" ShowInSelectColumns="No"> </ISWebGrid:WebGridColumn> </Columns> </RootTable> <ClientBindingSettings DataSourceType="WebService" ServiceUrl="PriceSearchWS.asmx"> <ServiceMethods SelectMethod="getPricesProductInfo" /> <ServiceEvents Selecting="Service_Selecting" /> </ClientBindingSettings> </ISWebGrid:WebGrid> </div> <asp:HiddenField ID="HiddenAccountId" Value="" runat="server" /> <asp:HiddenField ID="HiddenUserID" Value="00000000-0000-0000-0000-000000000000" runat="server" /> <asp:HiddenField ID="HiddenApplyProductDist" Value="false" runat="server" /> </form> </body> </html>
WebGrid has FormatConditions feature which allows you to quickly define formatting based on specified condition right from WebGrid’s designer. The formatting can be applied to either specified TargetColumn or entire row.
Example:
<ISWebGrid:WebGrid ID="WebGrid1" runat="server" ...> <RootTable DataKeyField="CustomerID" Caption="Customers" GridLineStyle="NotSet"> <FormatConditions> <ISWebGrid:WebGridFormatCondition ConditionText="UK" Name="FormatCondition0" ColumnMember="Country"> <FormatStyle ForeColor="#C00000"> </FormatStyle> </ISWebGrid:WebGridFormatCondition> <ISWebGrid:WebGridFormatCondition TargetObject="Cell" ConditionText="Madrid" Name="FormatCondition1" ColumnMember="City" TargetColumnMember="City"> <FormatStyle Font-Bold="True"> </FormatStyle> </ISWebGrid:WebGridFormatCondition> <ISWebGrid:WebGridFormatCondition Name="FormatCondition2" CustomConditionText="[contactname] like 'a%' and [contacttitle] like 'Sales%'"> <FormatStyle Font-Underline="True"> </FormatStyle> </ISWebGrid:WebGridFormatCondition> </FormatConditions> <Columns> ... </Columns> </RootTable> </ISWebGrid:WebGrid>
There are three formatting conditions specified in the above snippet code of WebGrid.
When viewed in browser, the grid will becomes:
For more information about WebGridFormatCondition feature, please check FormatCondition.aspx (V3.5/FormatCondition.aspx) file in the WebGrid Tutorial (click start > All Programs > Intersoft WebUI Studio 2012 R1 SP1 > Intersoft WebUI Studio for ASP.NET > WebGrid 8 > C# Tutorials).
Alternatively, you can also set the style of a cell based on a certain condition in InitializeRow server side event of WebGrid. The following snippet code shows how set the fore color of cell under the “ReorderLevel” column.
protected void WebGrid1_InitializeRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e) { // do some validation if (Convert.ToString(e.Row.Cells.GetNamedItem("CategoryID").Text) == "1" || Convert.ToString(e.Row.Cells.GetNamedItem("CategoryID").Text) == "7") { ... e.Row.Cells.GetNamedItem("ReorderLevel").Style.ForeColor = System.Drawing.Color.Red; } }
I have tried to apply the code in CustomizeCellAlignment.aspx sample file of WebGrid ((click start > All Programs > Intersoft WebUI Studio 2012 R1 SP1 > Intersoft WebUI Studio for ASP.NET > WebGrid 8 > C# Sample) and the grid will becomes:
Hope this helps.
In order to set the color in the client side, you may try following JavaScript function.
function button1_onclick() { var WebGrid1 = ISGetObject("WebGrid1"); var RootTable = WebGrid1.GetRootTable(); var FirstRow = RootTable.GetRow(0); var Cells = FirstRow.GetCells(); Cells.GetNamedItem("CompanyName").GetElement().style.color = "red"; return true; }
The JavaScript function will set the CompanyName cell’s fore color of the first row. You should modify the script to fit with your specific scenario.
In order to set the fore color of text – under a specific column, for example: the “NetAmount” column – into red color based on certain condition, first we would need to obtain the cell’s element and then set the color property.
OnSynchronizeCell is invoked when WebGridCell object is synchronized to the rendered element. We can use this event to perform post-rendering tasks, such as accessing DOM elements to customize styles, or call cell’s API to perform cell-specific functions.
The snippet code below will set the fore color of cell into red based on the following condition: The cell is located under “LastName” column AND the cell’s value is equal to “Davolio”.
function WebGrid1_OnSynchronizeCell(id, cell) { var grid = ISGetObject(id); // Check the column name of the cell if (cell.Name == "LastName") { // Validation goes in here if (cell.Value == "Davolio") { cell.GetElement().style.color = "Red"; } } }
This should help.
WebGrid1_OnSynchronizeCell
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname