This is a migrated thread and some comments may be shown as answers.

EnableLinqExpressions and decimal values in filter

3 Answers 62 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 20 Aug 2014, 12:08 PM
Hi,

i´m using Telerik 2014.1.403.35 and my Datasource is a DataTable (MSSQL)

<telerik:RadGrid EnableLinqExpressions="true" OnItemDataBound="RadGrid_ItemDataBound" OnItemCommand="RadGrid1_ItemCommand" ID="rgAbrechnungen" runat="server" GridLines="None" AutoGenerateColumns="False" Skin="Default" AllowSorting="true" AllowFilteringByColumn="true">

<telerik:GridTemplateColumn  UniqueName="zeichnungssumme" AutoPostBackOnFilter="true"  ShowFilterIcon="false" SortExpression="Zeichnungssumme" DataField="Zeichnungssumme"        HeaderText="Zeichnungssumme"      DataType="System.Decimal"  ItemStyle-HorizontalAlign="right" HeaderStyle-HorizontalAlign="right">
                    <ItemTemplate>
                       <%#Eval("Zeichnungssumme", "{0:#,0.00}")%> EUR
                    </ItemTemplate>
                </telerik:GridTemplateColumn>

When i´m trying to filter for a decimal value (for example: 7143,05) and EnableLinqExpressions is true,
the filtering working correctly.
But if i set the EnableLinqExpressions to false, and enter my decimal value (7143,05) in my filterbox and push return, my page do a postback, but nothing more happens.
It should filter my Values and show me the one existing row with my entered value like with EnableLinqExpressions="true".

I need to set EnableLinqExpressions to false cause if i don´t, a lot of exceptions where thrown.
For example my datetime column:
If i don´t type the correct format (dd.mm.yyyy) my grid throws a exception with "no correct DateTime format".
Further, if i try to filter my System.decimal column and type something like "10.000,05", it throws an "Identifier expected" exception.

Thanks in advance

Marc Beckord

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 22 Aug 2014, 05:44 AM
Hi Marc,

I was not able to replicate this issue at my end. Please try the sample code snippet which works fine at my end. Provide your full code snippet for further help.

ASPX:
<telerik:RadGrid ID="rgrdSample" runat="server" AutoGenerateColumns="false" AllowPaging="true" AllowSorting="true" AllowFilteringByColumn="true" EnableLinqExpressions="false" OnNeedDataSource="rgrdSample_NeedDataSource">
    <MasterTableView>
        <Columns>
            <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID" />
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name" />
            <telerik:GridTemplateColumn UniqueName="Number" AutoPostBackOnFilter="true" ShowFilterIcon="false" SortExpression="Number" DataField="Number" HeaderText="Number" DataType="System.Decimal" ItemStyle-HorizontalAlign="right" HeaderStyle-HorizontalAlign="right">
                <ItemTemplate>
                    <%#Eval("Number", "{0:#,0.00}")%>
                    EUR
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void rgrdSample_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
        dynamic data = new[] {
    new { ID = 1, Name = "Name1", Number=12.36},
    new { ID = 2, Name = "Name2", Number=10.28},
    new { ID = 3, Name = "Name3", Number=963.2},
    new { ID = 4, Name = "Name4", Number=10.28},
    new { ID = 5, Name = "Name5", Number=7143.05},
    new { ID = 6, Name = "Name6", Number=567.25},
    new { ID = 7, Name = "Name7", Number=100.02},
    new { ID = 8, Name = "Name8", Number=100.02},
    new { ID = 9, Name = "Name9", Number=89632.25}
    };
 rgrdSample.DataSource = data;
}

Thanks,
Princy

0
Marc
Top achievements
Rank 1
answered on 22 Aug 2014, 06:28 AM
Hi Princy,

first, thanks for your reply.
Unfortunately it still doesn´t work.

If i try to filter for "7143,05" in my grid, the exceptions were still thrown.
Please try to use also a "comma" as delimiter in your "number" column. (12,36 / 963,2 / 7143,05)

For your information, my column "Zeichnungssumme" is in "money" format in SQL.



Here is my full code snipped

ASPX:

<telerik:RadGrid EnableLinqExpressions="true" OnItemDataBound="RadGrid_ItemDataBound" OnItemCommand="RadGrid1_ItemCommand" ID="rgAbrechnungen" runat="server" GridLines="None" AutoGenerateColumns="False" Skin="Default" AllowSorting="true" AllowFilteringByColumn="true">
     <ClientSettings>
         <Scrolling AllowScroll="true" UseStaticHeaders="true" />
     </ClientSettings>
     <MasterTableView >
     <SortExpressions>
         <telerik:GridSortExpression FieldName="Abr_Nummer" SortOrder="Ascending" />
     </SortExpressions>
      <NoRecordsTemplate>
   <div>
     Keine Daten vorhanden</div>
 </NoRecordsTemplate>
         <Columns>
             <telerik:GridButtonColumn DataTextField="Abr_Nummer"  DataType="System.Decimal"  HeaderText="Abrechnungsnummer" ItemStyle-HorizontalAlign="left" ButtonType="LinkButton" CommandName="download" />
              
             <telerik:GridBoundColumn AutoPostBackOnFilter="true" ShowFilterIcon="false" DataField="date_AbrLauf_Datum"         HeaderText="Abrechnungsdatum"   DataType="System.Datetime" DataFormatString="{0:d}" ItemStyle-HorizontalAlign="left" HeaderStyle-HorizontalAlign="left" />
             <telerik:GridTemplateColumn  UniqueName="zeichnungssumme" AutoPostBackOnFilter="true"  ShowFilterIcon="false" SortExpression="Zeichnungssumme" DataField="Zeichnungssumme"        HeaderText="Zeichnungssumme"      DataType="System.Decimal"  ItemStyle-HorizontalAlign="right" HeaderStyle-HorizontalAlign="right">
                 <ItemTemplate>
                    <%#Eval("Zeichnungssumme", "{0:#,0.00}")%> EUR
                 </ItemTemplate>
             </telerik:GridTemplateColumn>
             <telerik:GridBoundColumn ShowFilterIcon="false" DataField="Abr_GesamtbetragAgioEUR"    HeaderText="Agio in EUR"        DataType="System.Decimal" DataFormatString="{0:#,##0.00}" ItemStyle-HorizontalAlign="left" HeaderStyle-HorizontalAlign="left" Visible="false"/>
             <telerik:GridTemplateColumn  UniqueName="provisionsbetrag" ShowFilterIcon="false" AutoPostBackOnFilter="true" SortExpression="Abr_ZahlbetragEUR" DataField="Abr_ZahlbetragEUR"          HeaderText="Provisionsbetrag"  DataType="System.Decimal"  ItemStyle-HorizontalAlign="right" HeaderStyle-HorizontalAlign="right">
                 <ItemTemplate>
                     <%#Eval("Abr_ZahlbetragEUR", "{0:#,0.00}")%> EUR
                 </ItemTemplate>
             </telerik:GridTemplateColumn>
             <telerik:GridBoundColumn ShowFilterIcon="false" DataField="uid_Abr_Key" Display="false"   HeaderText="ID"  DataType="System.Decimal" ItemStyle-HorizontalAlign="right" HeaderStyle-HorizontalAlign="right"/>
              
              
         </Columns>
         <RowIndicatorColumn>
             <HeaderStyle Width="20px" />
         </RowIndicatorColumn>
         <ExpandCollapseColumn>
             <HeaderStyle Width="20px" />
         </ExpandCollapseColumn>
     </MasterTableView>
     <FilterMenu EnableTheming="True" Skin="Sunset">
         <CollapseAnimation Duration="200" Type="OutQuint" />
     </FilterMenu>
 </telerik:RadGrid>

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["Login_Vertriebspartner_Object"] == null)
        Response.Redirect("~/Login.aspx");
 
    vp = (Vertriebspartner)Session["Login_Vertriebspartner_Object"];
 
 
    // This function returns my DataTable
    rgAbrechnungen.DataSource = AbrechnungManager.GetAbrechnungenForVertriebspartner(this.AppContext, vp.Guid);
    rgAbrechnungen.DataBind();
 
}


if you need more informations, just ask me ;)

best,
Marc
0
Eyup
Telerik team
answered on 22 Aug 2014, 02:24 PM
Hello Marc,

Please note that using DataBind() to bind the grid is not recommended. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Advanced Data Binding


Please make the suggested modification and let me know about the result.

In addition, you can try to set a different culture to the grid, for example "de-DE".

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Filter
Asked by
Marc
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Marc
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or