Hi I have some transactions that I am trying to bind to a radgrid. The transactions are being read from an XML file. I am using VB.NET and would like to change some of the values being bound from string to decimal.
Here is my code for the grid.
Here is the XML:
The grid is being bound with all the proper values but the miles value needs to be a long and the amount needs to be a decimal.
Here is how im binding the grid:
Now I tried the following to but it does not work.
Can anyone please point me in the right direction? The end reason is that I would like to have totals for those two columns in the footer and the Aggregate="Sum" does not work if the bound item is of type string. Thanks
Mustafa
Here is my code for the grid.
| <telerik:RadGrid ID="_pastItemsGrid" runat="server" AllowMultiRowSelection="true" |
| ShowFooter="true" AutoGenerateColumns="false" OnItemDataBound="_pastItemsGrid_ItemDataBound"> |
| <HeaderStyle Font-Bold="true" HorizontalAlign="Left" /> |
| <PagerStyle Mode="NextPrevAndNumeric" /> |
| <ClientSettings> |
| <Selecting AllowRowSelect="true" /> |
| </ClientSettings> |
| <MasterTableView DataKeyNames="TranID"> |
| <Columns> |
| <telerik:GridBoundColumn HeaderText="Date" DataField="Date" /> |
| <telerik:GridBoundColumn HeaderText="Description" DataField="Description" /> |
| <telerik:GridBoundColumn HeaderText="Miles" DataField="Miles" DataType="System.Double" /> |
| <telerik:GridBoundColumn HeaderText="Amount" DataField="Amount" DataType="System.Decimal" |
| DataFormatString="{0:C2}" /> |
| <telerik:GridClientSelectColumn HeaderText="Select" UniqueName="checkSelect" /> |
| </Columns> |
| <NoRecordsTemplate> |
| <div> |
| There were no records found.</div> |
| </NoRecordsTemplate> |
| </MasterTableView> |
| </telerik:RadGrid> |
Here is the XML:
| <Transcations> |
| <Transaction TranID="01"> |
| <Date>01/22/09</Date> |
| <Description>Target</Description> |
| <Miles>50400</Miles> |
| <Amount>504.46</Amount> |
| </Transaction> |
| <Transaction TranID="02"> |
| <Date>01/23/09</Date> |
| <Description>Ann Taylor Loft</Description> |
| <Miles>30500</Miles> |
| <Amount>305.50</Amount> |
| </Transaction> |
| <Transaction TranID="03"> |
| <Date>01/24/09</Date> |
| <Description>Dick's Sporting Goods</Description> |
| <Miles>5000</Miles> |
| <Amount>50.32</Amount> |
| </Transaction> |
| </Transcations> |
The grid is being bound with all the proper values but the miles value needs to be a long and the amount needs to be a decimal.
Here is how im binding the grid:
| Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
| Dim ds As New DataSet |
| ds.ReadXml(Server.MapPath("../Transactions.xml")) |
| _pastItemsGrid.DataSource = ds |
| _pastItemsGrid.DataBind() |
| End Sub |
Now I tried the following to but it does not work.
| Protected Sub _pastItemsGrid_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles _pastItemsGrid.ItemDataBound |
| If TypeOf e.Item Is GridDataItem Then |
| Dim accrued As New Double |
| Dim amount As New Decimal |
| accrued = CDbl(e.Item.DataItem(2)) |
| e.Item.DataItem(2) = accrued |
| amount = CDec(e.Item.DataItem(3)) |
| e.Item.DataItem(3) = amount |
| End If |
| End Sub |
Can anyone please point me in the right direction? The end reason is that I would like to have totals for those two columns in the footer and the Aggregate="Sum" does not work if the bound item is of type string. Thanks
Mustafa