473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Datagrid -True or False column

I got a true or false column in my Datagrid, The datafield is "bit" in the
sql tables,
However, I want to display "A" if the field is true, "B" is false .
Is this possible to do ?? or I should add one more field in my tables and
put "A"or "B" in it ? thanks
Nov 21 '05 #1
2 1468
ben
I use the following code to alter my datagrid:

Sub Datagrid4_ItemDataBound(ByVal sender As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs)
'Get the column number based on the header text
Dim Column As Integer = IndexByName(Datagrid1, "Name")

If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType =
ListItemType.Item Then 'If this is not a header or footer row
'then change the contents of your datagrid cell based on an if statement
if e.Item.Cells(Column).Text = "1" then
e.Item.Cells(Column).Text= "A"
End If
End Sub

..
Shared Function IndexByName(ByVal grid As
System.Web.UI.WebControls.DataGrid, ByVal name As String) As Integer
Dim col As Integer
For col = 0 To grid.Columns.Count - 1 Step col + 1
If grid.Columns(col).HeaderText = name Then
Return col
End If
Next
Return -1
End Function

I havent tested this code. I changed mine to do what you are trying to
do...

HTH
Nov 21 '05 #2
Hi,

Create a class that inherits from datagridtextboxcolumn to do that.
Add the class to the grids tablestyle. Here is an example that displays yes
or no
Dim ds As New DataSet

Dim phasetable As DataTable

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim conn As SqlConnection

Dim strConn As String

Dim strSQL As String

Dim da As SqlDataAdapter

'strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

'strConn &= "Data Source = Northwind.mdb;"

strConn = "Server = (local);"

strConn &= "Database = NorthWind;"

strConn &= "Integrated Security = SSPI;"

conn = New SqlConnection(strConn)

da = New SqlDataAdapter("Select * From Products", conn)

da.Fill(ds, "Products")


Dim ts As New DataGridTableStyle

ts.MappingName = ds.Tables("Products").TableName

Dim colDiscontinued As New YesNoColumn

With colDiscontinued

..MappingName = "Discontinued"

..HeaderText = "Discontinued"

..Width = 80

End With

Dim colName As New DataGridTextBoxColumn

With colName

..MappingName = "ProductName"

..HeaderText = "Product Name"

..Width = 180

End With

ts.GridColumnStyles.Add(colName)

ts.GridColumnStyles.Add(colDiscontinued)

DataGrid1.TableStyles.Add(ts)

phasetable = ds.Tables("Products")

DataGrid1.DataSource = phasetable

ts = Nothing

colDiscontinued = Nothing

colName = Nothing

End Sub

The datagrid column

Public Class YesNoColumn

Inherits DataGridTextBoxColumn



Public Sub New()

Me.ReadOnly = True

End Sub

Protected Overrides Function GetColumnValueAtRow(ByVal source As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Object

Dim b As Boolean = False

Try

b = CType(MyBase.GetColumnValueAtRow(source, rowNum), Boolean)

Catch ex As Exception

End Try

If b = True Then

Return "Yes"

Else

Return "No"

End If

End Function

End Class

Ken

--------------------------
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:eU**************@TK2MSFTNGP09.phx.gbl...
I got a true or false column in my Datagrid, The datafield is "bit" in the
sql tables,
However, I want to display "A" if the field is true, "B" is false .
Is this possible to do ?? or I should add one more field in my tables and
put "A"or "B" in it ? thanks

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: GregM | last post by:
I have a read only datagrid that is designed to coordinate itself with textboxes. When the user clicks on a row in the datagrid, detailed data for that row is displayed for editing in the...
5
by: BBFrost | last post by:
Win2000 ..Net 1.1 SP1 c# using Visual Studio Ok, I'm currently in a "knock down - drag out" tussle with the .Net 1.1 datagrid. I've come to realize that a 'block' of rows highlighted within...
3
by: Ryan Liu | last post by:
Hi there, I got a NullReferenceException when delete last row in a datagrid. I had hard time to solve since it does not occur in my own code. I put a datagrid in my inherited user control,...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
7
by: Scott Schluer | last post by:
Hi All, I have a functioning datagrid on "Page 1" that displays order information for a single order (this is for an e-commerce site). It's actually a combination of a couple datagrids to...
0
by: BK Kim | last post by:
Hello. I am trying to use dataGrid in a dataGrid, meaning first DataGrid displays some information and on each row, it is going to have another datagrid to display detailed information. I was...
1
by: thegame | last post by:
Filling One DataGrid Based on Selection from Another DataGrid - Both in Separate User Controls Hello, I have an interesting dilemma. I have an ASPX page with two user controls (two ASCXs). ...
7
by: Dave | last post by:
Are there any add-on products or samples available that can do the following in an vb.net datagrid I want to compare 2 rows in a datagrid - one row from one database and another row for another...
1
by: arupasna | last post by:
hi everybody, 1) I am a dotnet programmer seeking for urgent help, i have a datagrid, there is textbox. if u hit the textbox to type anything a further new datagrid window will be open. ...
8
by: Brock | last post by:
I am trying to populate a Crystal Report from data in my DataGrid. The reason for this is that I want the user to be able to change values without updating the database, but still have their report...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.