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

[Solved] Currency TextBox Template for Datatable bound Grid

1 Answer 96 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Luciano Kaesemodel
Top achievements
Rank 1
Luciano Kaesemodel asked on 30 Nov 2012, 12:04 PM
Hello everyone.
I have a scenario where I need to show a query using pivot table (show values by year quarter, so I don't know how many columns the grid will have). I have bound a telerik mvc grid to a datatable.
More than that...I need to make some of those columns editable (the editable ones must be every column but the first 3)
To every System.Data.Datarow, I have a cell with an unique ID.
So, I made a template using telerik mvc currency textBox this way:

@model System.Data.DataTable
<div id="placeHolderDadosFinanceiros">
    @(
 Html.Telerik().Grid(Model)
                  .Name("GridDadosFinanceiros")
                  .Columns(columns =>
                   {
                       int columnIndex = 0;
                       foreach (System.Data.DataColumn column in Model.Columns)
                       {
 
                           if (columnIndex < 4)
                           {
                               columns.Bound(column.DataType, column.ColumnName)
                                   .Width(80);
                           }
                           else
                           {
                               string[] nome = Model.Columns[columnIndex].ColumnName.Split('_');
                               columns
                                   .Bound(column.DataType, column.ColumnName)
                                   .Template(@<text>@Html.Telerik()
                                                            .CurrencyTextBox()
                                                            .Value(0)
                                                            .Name("txtValue" + column.ColumnName + "<#= " + Model.Columns[1].ColumnName + " #>")
                                                            .DecimalDigits(4)
                                                            .IncrementStep((decimal)0.005)
                                                            .ToHtmlString()</text>)
                                       .Title(string.Concat(nome[0].Replace("T", string.Empty), "º Trimestre (", nome[1], ")"))
                                   .ClientTemplate(Html.Telerik()
                                       .CurrencyTextBox()
                                       .Value(0)
                                       .Name("txtValue" + column.ColumnName + "<#= " + Model.Columns[1].ColumnName + " #>")
                                       .DecimalDigits(4)
                                       .IncrementStep((decimal)0.005)
                                       .ToHtmlString());
                           }
                           columnIndex++;
                       }
                   })
                  .DataBinding(dataBinding => dataBinding.Ajax()
                      .Select("GridDadosFinanceirosSelect", "Simulador"))
                  .Pageable(p => p.PageSize(15))
                  .Sortable()
                  .Filterable()
)
</div>

My plan is to manual (jquery) search the CurrencyTextBoxes for changes after the Client hit a Save Button.
My issue is: The CurrencyTextBox in the grid show's no value at first glance, unless you have focus on the field, then the values are displayed.
Any ideas what is causing this behavior?

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 05 Dec 2012, 09:44 AM
Hello Liciano,

We could not tell you what exactly is going wrong, the code you shared looks fine and the initial value of 0 should be displayed when the Grid is loaded.

Sharing a sample runnable project could would help is pinpoint the exact reason for that behavior.

Regards,
Petur Subev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
Tags
Grid
Asked by
Luciano Kaesemodel
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or