I need to address the following scenario : There is a hierarchical grid, that on the back end has values stored as floating point,
But only one row is the one that floating point numbers can be entered. This row has custom formatting as {0:N5}.
The issue that is needed to be addressed is to prevent user to enter decimal point in any other cell that does not belong to the row with floating point numbers (((string)e.Row.Items.GetValue(2) == "TAXRATE") ) Basically in any cell except on the “TAXRATE” row, only whole (integer) numbers can be entered. Attached sample, please use it to show how… upload is broken, so below is the source contents...
lrR4Data.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="lrR4Data.aspx.cs" Inherits="WHG.lrR4Data" %>
<%@ Register assembly="Infragistics45.Web.v20.1, Version=20.1.20201.24, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.Web.UI.GridControls" tagprefix="ig" %><%@ Register assembly="Infragistics45.Web.v20.1, Version=20.1.20201.24, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.Web.UI" tagprefix="ig" %>
<!DOCTYPE html>
<html xmlns="">www.w3.org/.../xhtml"><head runat="server"> <title></title></head><body style="height: 81px"> <%-- OnDataBound="lr4whdg_DataBound"--%>
<form id="form1" runat="server"> <ig:WebHierarchicalDataGrid ID="lr4whdg" runat="server" Height="400px" AutoGenerateColumns="False" Key="idMain" StyleSetName="Claymation" DataMember="MRC_FRANCHISE_Main" InitialDataBindDepth="1" AutoGenerateBands="False" DataKeyFields="LINE" OnRowUpdating="lr4whdg_RowUpdating" EnableAjax="False" Width="680px" OnInitializeRow="lr4whdg_InitializeRow"> <Bands> <ig:Band AutoGenerateColumns="False" DataKeyFields="LINE" DataMember="MRC_FRANCHISE_Adjust" OnRowUpdating="lr4whdg_RowUpdating" Key="idRow" Width=""> <Columns> <ig:BoundDataField DataFieldName="idRow" Key="idRow" Hidden="True" DataType="System.Int32"> <Header Text="idRow" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="idMain" DataType="System.Int32" Key="idMain" Hidden="True"> <Header Text="idMain"> </Header> <Footer Text="idMain"> </Footer> </ig:BoundDataField> <ig:BoundDataField DataFieldName="TAXNAME" DataType="System.String" Key="TAXNAME" Hidden="True"> <Header Text="TAXNAME"> </Header> </ig:BoundDataField> <ig:BoundDataField DataFieldName="TAX_DESC" Key="TAX_DESC" CssClass="BoldMaroonAdjColumn" Width="250px"> <Header Text="Account"> </Header> </ig:BoundDataField> <ig:BoundDataField DataFieldName="LINE" Key="LINE" Hidden="True"> <Header Text="Line" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Total" Key="Total" DataType="System.Double" CssClass="BoldColumn" DataFormatString="{0:N0}" Width="70px"> <Header Text="Total" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="a5" DataFormatString="{0:N0}" DataType="System.Double" Key="a5" Width="70px"> <Header Text="a5"> </Header> </ig:BoundDataField> <ig:BoundDataField DataFieldName="a6" DataFormatString="{0:N0}" DataType="System.Double" Key="a6" Width="70px"> <Header Text="a6"> </Header> </ig:BoundDataField> </Columns> <Behaviors> <ig:EditingCore BatchUpdating="True"> <Behaviors> <ig:CellEditing> <ColumnSettings> <ig:EditingColumnSetting ColumnKey="TAX_DESC" ReadOnly="True" /> <ig:EditingColumnSetting ColumnKey="Total" ReadOnly="True" /> </ColumnSettings> <EditModeActions MouseClick="Single" /> </ig:CellEditing> </Behaviors> </ig:EditingCore> </Behaviors> </ig:Band> </Bands> <EditorProviders> <ig:NumericEditorProvider ID="NumEd"> <EditorControl ClientIDMode="Predictable" NullValue="0" Nullable="False" NullText="0" SpinDelta="0" MinDecimalPlaces="5"></EditorControl> </ig:NumericEditorProvider> </EditorProviders> <Columns> <ig:BoundDataField DataFieldName="idMain" DataType="System.Int32" Key="idMain" Width="40px"> <Header Text="idMain"> </Header> </ig:BoundDataField> <ig:BoundDataField DataFieldName="TAXNAME" Key="TAXNAME" Hidden="true" Width="70px"></ig:BoundDataField> <ig:BoundDataField DataFieldName="TAX_DESC" Key="TAX_DESC" Width="250px"> <Header Text="Account" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="LINE" Key="LINE" Hidden="True"> <Header Text="Line" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="calc" DataType="System.String" Hidden="True" Key="calc"> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Total" Key="Total" DataType="System.Double" CssClass="BoldColumn" DataFormatString="{0:N0}" Width="70px"> <Header Text="Total" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="a5" DataFormatString="{0:N0}" DataType="System.Double" Key="a5" Width="70px"> <Header Text="a5"> </Header> </ig:BoundDataField> <ig:BoundDataField DataFieldName="a6" DataFormatString="{0:N0}" DataType="System.Double" Key="a6" Width="70px"> <Header Text="a6"> </Header> </ig:BoundDataField> </Columns> <Behaviors> <ig:EditingCore AutoCRUD="False" EnableInheritance="True" BatchUpdating="True"> <Behaviors> <ig:CellEditing EnableInheritance="True"> <ColumnSettings> <ig:EditingColumnSetting ColumnKey="TAX_DESC" ReadOnly="True" /> <ig:EditingColumnSetting ColumnKey="Total" ReadOnly="True" /> </ColumnSettings> <EditModeActions MouseClick="Single" /> </ig:CellEditing> </Behaviors> </ig:EditingCore> <ig:Activation></ig:Activation> </Behaviors> </ig:WebHierarchicalDataGrid> <br /> <asp:Button ID="Button1" runat="server" Height="30px" Text="Post" Width="193px" /> <ig:WebScriptManager ID="WebScriptManager1" runat="server"> </ig:WebScriptManager> <br /> <br /> </form>
</body></html>
lrR4Data.aspx.cs
using System;using System.Collections.Generic;
using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using WHG.AppData;
using Infragistics.Web.UI.GridControls;using Infragistics.Web.UI.ListControls;using Infragistics.Web.UI.DataSourceControls;
namespace WHG{ public partial class lrR4Data : System.Web.UI.Page { ExhibitLR4HierarchialDS hds; private const int FirstDataColumnNo_MainGrid = 5; ////5; ///4; // zero based, skip those: calc, LINE, TAX_DESC, Total, --> a5, a6,........... private const int FirstDataColumnNo_aDJGrid = 5; ///4; // zero based, skip those: line, idRow, TAX_DESC, Total, --> a5, a6,...........
//counter to determine the current index int currentRow = 0; int currentCol = 0; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) {
hds = CreateHds(); lr4whdg.DataSource = hds; lr4whdg.DataBind(); Session["hds"] = hds; } else { hds = (ExhibitLR4HierarchialDS)Session["hds"]; lr4whdg.DataSource = hds; lr4whdg.DataBind(); } }
protected void lr4whdg_RowUpdating(object sender, RowUpdatingEventArgs e) { //int idMain; //int idRow; bool ThisIsMainGrid; // i.e. parent // System.Threading.Thread.Sleep(5000); // 5 sec e.Cancel = true; //DataSet CalcDS = (DataSet)Session["MrcFranData"]; ContainerGrid g = (ContainerGrid)sender;
if ((ControlDataField)g.FindColumn("idRow") != null) ThisIsMainGrid = false; else ThisIsMainGrid = true;
g.DataBind(); currentRow = 0; // g.RequestFullAsyncRender();
}
protected void lr4whdg_InitializeRow(object sender, RowEventArgs e) { if ((string)e.Row.Items.GetValue(2) == "TAXRATE") // tax rate line {
for (int i = 3; i < e.Row.Items.Count; i++) // start from total { e.Row.Items[i].Text = string.Format("{0:N5}", e.Row.Items[i].Value); } } }
private ExhibitLR4HierarchialDS CreateHds() { ExhibitLR4HierarchialDS hds = new ExhibitLR4HierarchialDS(); ExhibitLR4HierarchialDS.MRC_FRANCHISE_MainRow mRow; ExhibitLR4HierarchialDS.MRC_FRANCHISE_AdjustRow aRow;
mRow = hds.MRC_FRANCHISE_Main.NewMRC_FRANCHISE_MainRow(); mRow.idMain = 1; mRow.TAXNAME = "NTS"; mRow.TAX_DESC = "NTS Descr"; mRow.LINE = 100; mRow.calc = "<100>"; mRow.Total = 1111.101; mRow.a5 = 1111.202; mRow.a6 = 1111.303; hds.MRC_FRANCHISE_Main.AddMRC_FRANCHISE_MainRow(mRow);
mRow = hds.MRC_FRANCHISE_Main.NewMRC_FRANCHISE_MainRow(); mRow.idMain = 2; mRow.TAXNAME = "COGS"; mRow.TAX_DESC = "COGS Descr"; mRow.LINE = 200; mRow.calc = "<200>"; mRow.Total = 22222.101; mRow.a5 = 22222.202; mRow.a6 = 22222.303; hds.MRC_FRANCHISE_Main.AddMRC_FRANCHISE_MainRow(mRow);
mRow = hds.MRC_FRANCHISE_Main.NewMRC_FRANCHISE_MainRow(); mRow.idMain = 3; mRow.TAXNAME = "ADJUST"; mRow.TAX_DESC = "ADJUST Descr"; mRow.LINE = 300; mRow.calc = "<300>"; mRow.Total = 3333.101; mRow.a5 = 333.202; mRow.a6 = 3333.303; hds.MRC_FRANCHISE_Main.AddMRC_FRANCHISE_MainRow(mRow);
mRow = hds.MRC_FRANCHISE_Main.NewMRC_FRANCHISE_MainRow(); mRow.idMain = 4; mRow.TAXNAME = "TAXRATE"; mRow.TAX_DESC = "TAXRATE"; mRow.LINE = 400; mRow.calc = "<400>"; mRow.Total = 25.12345; mRow.a5 = 25.67891; mRow.a6 = 25.23456; hds.MRC_FRANCHISE_Main.AddMRC_FRANCHISE_MainRow(mRow);
mRow = hds.MRC_FRANCHISE_Main.NewMRC_FRANCHISE_MainRow(); mRow.idMain = 5; mRow.TAXNAME = "TAX_RESERV"; mRow.TAX_DESC = "TAX_RESERV Descr"; mRow.LINE = 310; mRow.calc = " "; mRow.Total = 55555.101; mRow.a5 = 5555.202; mRow.a6 = 5555.303; hds.MRC_FRANCHISE_Main.AddMRC_FRANCHISE_MainRow(mRow);
// ------------------------------------------------------- // --------------------------------------------------------
aRow = hds.MRC_FRANCHISE_Adjust.NewMRC_FRANCHISE_AdjustRow(); aRow.idRow = 1; aRow.idMain = 3; aRow.TAXNAME = "ADJ1"; aRow.TAX_DESC = "ADJ1 Descr"; aRow.LINE = 310; aRow.calc = " "; aRow.Total = 15555.55; aRow.a5 = 1555.55; aRow.a6 = 1555.55; hds.MRC_FRANCHISE_Adjust.AddMRC_FRANCHISE_AdjustRow(aRow);
aRow = hds.MRC_FRANCHISE_Adjust.NewMRC_FRANCHISE_AdjustRow(); aRow.idRow = 2; aRow.idMain = 3; aRow.TAXNAME = "ADJ2"; aRow.TAX_DESC = "ADJ2 Descr"; aRow.LINE = 320; aRow.calc = " "; aRow.Total = 2555.55; aRow.a5 = 2556.56; aRow.a6 = 2557.57; hds.MRC_FRANCHISE_Adjust.AddMRC_FRANCHISE_AdjustRow(aRow);
aRow = hds.MRC_FRANCHISE_Adjust.NewMRC_FRANCHISE_AdjustRow(); aRow.idRow = 3; aRow.idMain = 3; aRow.TAXNAME = "ADJ3"; aRow.TAX_DESC = "ADJ3 Descr"; aRow.LINE = 330; aRow.calc = " "; aRow.Total = 3333.101; aRow.a5 = 333.202; aRow.a6 = 3333.303; hds.MRC_FRANCHISE_Adjust.AddMRC_FRANCHISE_AdjustRow(aRow);
aRow = hds.MRC_FRANCHISE_Adjust.NewMRC_FRANCHISE_AdjustRow(); aRow.idRow = 4; aRow.idMain = 3; aRow.TAXNAME = "ADJ4"; aRow.TAX_DESC = "ADJ4 Descr"; aRow.LINE = 340; aRow.calc = " "; aRow.Total = 25.678; aRow.a5 = 25.678; aRow.a6 = 25.678; hds.MRC_FRANCHISE_Adjust.AddMRC_FRANCHISE_AdjustRow(aRow);
aRow = hds.MRC_FRANCHISE_Adjust.NewMRC_FRANCHISE_AdjustRow(); aRow.idRow = 5; aRow.idMain = 3; aRow.TAXNAME = "ADJ5"; aRow.TAX_DESC = "ADJ5 Descr"; aRow.LINE = 350; aRow.calc = " "; aRow.Total = 55555.101; aRow.a5 = 5555.202; aRow.a6 = 5555.303; hds.MRC_FRANCHISE_Adjust.AddMRC_FRANCHISE_AdjustRow(aRow);
return hds; }
}}
Thanks
Hello,
Thank you for posting in our community.
My suggestion is to validate the fields on the client-side by handling the CellValueChanging event:
<Behaviors> <ig:EditingCore BatchUpdating="True"> <EditingClientEvents CellValueChanging="validate" /> <Behaviors> <ig:CellEditing> <EditModeActions MouseClick="Single" /> </ig:CellEditing> </Behaviors> </ig:EditingCore> <ig:Activation> </ig:Activation> </Behaviors>
<script> function validate(s, e) { var value = e.get_cell().get_row().get_cell(2).get_text(); if (value === "TAXRATE" && e.get_newValue() % 1 !== 0) e.set_cancel(true); } </script>
I have created and attached a small sample illustrating the desired behavior. Please test it on your side and let me know how it behaves. If this is not an accurate demonstration of what you are trying to achieve please feel free to modify it and send it back to me.
Please note that our forums accept attached files up to 1MB. By removing the bin and ig_res folder, the complete solution can be sent.
Looking forward to hearing from you.
46757.Sample.zip
Thanks, it worked well..
I am glad that you find my suggestion helpful.
Thank you for using Infragistics components.