Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 716
  • Last Modified:

Convert Boolean value to string in ASP.NET and MySQL server

I have several fields that are boolean (0,1) and  am binding them to my ASPX page with a gridview control. By default the table is showing check boxes, is it possible to convert the values to Y or N?
Dim MyDataSet As New DataSet()
            Mycommand.Fill(MyDataSet)
            GridView1.DataSource = MyDataSet
            GridView1.DataBind()
 
 
 
            Dim DGTruck As BoundField = New BoundField()
            Dim DGOper As BoundField = New BoundField()
            Dim DGShift As BoundField = New BoundField()
            Dim DGDate As BoundField = New BoundField()
            Dim DGV1 As BoundField = New CheckBoxField()
 
            DGTruck.DataField = "Truck"
            DGTruck.HeaderText = "Truck"
            DGTruck.SortExpression = "Truck"
 
            DGOper.DataField = "Operator"
            DGOper.HeaderText = "Operator"
            DGOper.SortExpression = "Operator"
 
            DGShift.DataField = "Shift"
            DGShift.HtmlEncode = False
            'DGShift.DataFormatString = "{0:n)"
            DGShift.HeaderText = "Shift"
            DGShift.SortExpression = "Shift"
 
            DGDate.DataField = "Date"
            DGDate.DataFormatString = "{0:MM/dd/yyyy}"
            DGDate.HtmlEncode = False
            DGDate.HeaderText = "Date"
            DGDate.SortExpression = "Date"
 
            DGV1.DataField = "V1"
            DGV1.HeaderText = "Condition"
            DGV1.SortExpression = "V1"
 
 
            GridView1.Columns.Add(DGTruck)
            GridView1.Columns.Add(DGOper)
            GridView1.Columns.Add(DGShift)
            GridView1.Columns.Add(DGDate)
            GridView1.Columns.Add(DGV1)
            GridView1.DataSource = MyDataSet
            GridView1.DataBind()

Open in new window

0
ITHelper80
Asked:
ITHelper80
1 Solution
 
kirihimeteCommented:
inside the gridview you will need a template field.  Inside the template field you can have a label and bind the labels text property to a database field. Then on RowDataBound() or GridViewDataBound() you can check the value coming in from the data and based on that logic display Y or N.  Does this make sense?
0
 
ITHelper80Author Commented:
Thanks but I found another way. I set the fields as New Boundfield() and then used the below code.
        Dim i As Integer = 4
        Do Until i = 25
            If e.Row.RowType = DataControlRowType.DataRow Then
                If e.Row.Cells(i).Text = True Then
                    e.Row.Cells(i).Text = "Y"
                    i = i + 1
                ElseIf e.Row.Cells(i).Text = False Then
                    e.Row.Cells(i).Text = "N"
                    i = i + 1
                End If
            Else
                Exit Do
            End If
        Loop

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now