combining datatypes in bound column

D

drdave

Hi,

In a bound column I have currency datatypes, but the client does not
like $ 0.00 and wants to show a blank instead.. I'm trying to use an if
statement to write out string.empty but it doesn't want to allow the
different datatype..

The currency amounts are stored as number in the db...

How can I accomplish this?

*** Code: ****


Public Sub CreateGrid()
'*** Make the year coming from the dropdown into a
datetime
Dim stryearval As String
stryearval = "01/01/" & ddlYears.SelectedItem.Value
'declare a new datagrid and set properties
Dim dgSearchResults As New DataGrid()
dgSearchResults.BorderWidth = Unit.Pixel(2)
dgSearchResults.CellPadding = 10
dgSearchResults.GridLines = GridLines.Both
dgSearchResults.ShowHeader = True
dgSearchResults.AutoGenerateColumns = False
dgSearchResults.HeaderStyle.Font.Bold = True



'add bound columns to the datagrid
Dim ProvCol As BoundColumn = New BoundColumn()
ProvCol.DataField = "provincename"
Dim EffDateCol As BoundColumn = New BoundColumn()
EffDateCol.DataField = "effective_date"
EffDateCol.DataFormatString = "{0:d}"

********************************************* This throws ERROR
****************************
********* System.FormatException: Input string was not in a correct
format ***************

Dim MinWageCol As BoundColumn = New BoundColumn()
MinWageCol.DataField = "minimum_wage_amount"
If MinWageCol.DataField = 0
MinWageCol.DataField = string.Empty
Else
MinWageCol.DataFormatString = "{0:c}"
End If
************************************************ Rest is good
**************************
MinWageCol.ItemStyle.HorizontalAlign = HorizontalAlign.Center
Dim VarCol As BoundColumn = New BoundColumn()
'Set Headers
If (Session("Language") Is "en-CA") Then
ProvCol.HeaderText = "Province"
EffDateCol.HeaderText = "Effective Date"
MinWageCol.HeaderText = "Minimum Wage"
VarCol.HeaderText = "Condition"
VarCol.DataField = "english_text"
Else
ProvCol.HeaderText = "Administration"
EffDateCol.HeaderText = "Date d'entrée en vigueur"
MinWageCol.HeaderText = "Salaire minimum"
VarCol.HeaderText = "Remarque"
VarCol.DataField = "french_text"
End If

** Code End ***

Am I missing some syntax??
 
W

Winista

hook into ItemCreated event for the grid and then override the text in the
cell directly.

Hi,

In a bound column I have currency datatypes, but the client does not
like $ 0.00 and wants to show a blank instead.. I'm trying to use an if
statement to write out string.empty but it doesn't want to allow the
different datatype..

The currency amounts are stored as number in the db...

How can I accomplish this?

*** Code: ****


Public Sub CreateGrid()
'*** Make the year coming from the dropdown into a
datetime
Dim stryearval As String
stryearval = "01/01/" & ddlYears.SelectedItem.Value
'declare a new datagrid and set properties
Dim dgSearchResults As New DataGrid()
dgSearchResults.BorderWidth = Unit.Pixel(2)
dgSearchResults.CellPadding = 10
dgSearchResults.GridLines = GridLines.Both
dgSearchResults.ShowHeader = True
dgSearchResults.AutoGenerateColumns = False
dgSearchResults.HeaderStyle.Font.Bold = True



'add bound columns to the datagrid
Dim ProvCol As BoundColumn = New BoundColumn()
ProvCol.DataField = "provincename"
Dim EffDateCol As BoundColumn = New BoundColumn()
EffDateCol.DataField = "effective_date"
EffDateCol.DataFormatString = "{0:d}"

********************************************* This throws ERROR
****************************
********* System.FormatException: Input string was not in a correct
format ***************

Dim MinWageCol As BoundColumn = New BoundColumn()
MinWageCol.DataField = "minimum_wage_amount"
If MinWageCol.DataField = 0
MinWageCol.DataField = string.Empty
Else
MinWageCol.DataFormatString = "{0:c}"
End If
************************************************ Rest is good
**************************
MinWageCol.ItemStyle.HorizontalAlign = HorizontalAlign.Center
Dim VarCol As BoundColumn = New BoundColumn()
'Set Headers
If (Session("Language") Is "en-CA") Then
ProvCol.HeaderText = "Province"
EffDateCol.HeaderText = "Effective Date"
MinWageCol.HeaderText = "Minimum Wage"
VarCol.HeaderText = "Condition"
VarCol.DataField = "english_text"
Else
ProvCol.HeaderText = "Administration"
EffDateCol.HeaderText = "Date d'entrée en vigueur"
MinWageCol.HeaderText = "Salaire minimum"
VarCol.HeaderText = "Remarque"
VarCol.DataField = "french_text"
End If

** Code End ***

Am I missing some syntax??
 
B

Bruno Piovan

I would change the select query.....

like,

SELECT (case Price when 0 then NULL else Price end) as Price from Table

Bruno



Hi,

In a bound column I have currency datatypes, but the client does not
like $ 0.00 and wants to show a blank instead.. I'm trying to use an if
statement to write out string.empty but it doesn't want to allow the
different datatype..

The currency amounts are stored as number in the db...

How can I accomplish this?

*** Code: ****


Public Sub CreateGrid()
'*** Make the year coming from the dropdown into a
datetime
Dim stryearval As String
stryearval = "01/01/" & ddlYears.SelectedItem.Value
'declare a new datagrid and set properties
Dim dgSearchResults As New DataGrid()
dgSearchResults.BorderWidth = Unit.Pixel(2)
dgSearchResults.CellPadding = 10
dgSearchResults.GridLines = GridLines.Both
dgSearchResults.ShowHeader = True
dgSearchResults.AutoGenerateColumns = False
dgSearchResults.HeaderStyle.Font.Bold = True



'add bound columns to the datagrid
Dim ProvCol As BoundColumn = New BoundColumn()
ProvCol.DataField = "provincename"
Dim EffDateCol As BoundColumn = New BoundColumn()
EffDateCol.DataField = "effective_date"
EffDateCol.DataFormatString = "{0:d}"

********************************************* This throws ERROR
****************************
********* System.FormatException: Input string was not in a correct
format ***************

Dim MinWageCol As BoundColumn = New BoundColumn()
MinWageCol.DataField = "minimum_wage_amount"
If MinWageCol.DataField = 0
MinWageCol.DataField = string.Empty
Else
MinWageCol.DataFormatString = "{0:c}"
End If
************************************************ Rest is good
**************************
MinWageCol.ItemStyle.HorizontalAlign = HorizontalAlign.Center
Dim VarCol As BoundColumn = New BoundColumn()
'Set Headers
If (Session("Language") Is "en-CA") Then
ProvCol.HeaderText = "Province"
EffDateCol.HeaderText = "Effective Date"
MinWageCol.HeaderText = "Minimum Wage"
VarCol.HeaderText = "Condition"
VarCol.DataField = "english_text"
Else
ProvCol.HeaderText = "Administration"
EffDateCol.HeaderText = "Date d'entrée en vigueur"
MinWageCol.HeaderText = "Salaire minimum"
VarCol.HeaderText = "Remarque"
VarCol.DataField = "french_text"
End If

** Code End ***

Am I missing some syntax??
 
W

Winista

Why would you want your data access layer be driven by UI? So if tomorow
client changes requirement, would you keep playing with your queries?
 
B

Bruno Piovan

I work this way....

much faster go and change a query than recompile code.....

I aways worked like this and never had problems..

Of course I use only stored procedures instead of tsql directly.....

Bruno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top