combining datatypes in bound column

Discussion in 'ASP .Net' started by drdave, Apr 10, 2006.

  1. drdave

    drdave Guest

    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??
     
    drdave, Apr 10, 2006
    #1
    1. Advertisements

  2. drdave

    Winista Guest

    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??
     
    Winista, Apr 10, 2006
    #2
    1. Advertisements

  3. drdave

    Guest Guest

    Use a TemplateField instead of a BoundField.
     
    Guest, Apr 10, 2006
    #3
  4. drdave

    Bruno Piovan Guest

    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??
     
    Bruno Piovan, Apr 10, 2006
    #4
  5. drdave

    Winista Guest

    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?
     
    Winista, Apr 10, 2006
    #5
  6. drdave

    Bruno Piovan Guest

    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
     
    Bruno Piovan, Apr 10, 2006
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.