Change in Display values in Boolean DataColumn in DataGridView

L

Lucky

hi guys,
it's me again. now days i'm learning DataGridView of .NET 2.0. i found
that some of the features are quite attractive but sometimes they are
not easy to modify and from that point our problem starts.

i've one bit column in my table in SQL SERVER 2000 Database. the
DataGridView displays it as "True" or "False". what i want to do is, i
want to make it display "Yes" or "No" instead.

i don't know what to do. As this is my first experience with asp.net
2.0 and before i've only done such thing in .NET 1.1 for desktop
application.

can someone please tell me how can i do this in asp.net 2.0
DataGridView?

i'm using SQL SERVER 2000 and .NET 2.0

Thanks,
Lucky
 
V

Vadivel Kumar

One way of dealing with this is, use RowDataBound event and use
GridViewRow object to get the currend binded row. Check its
CellCollection to see whether the binding value is true or false and
based on that set the value of the cell.

Please check the below code, which might usefull. I assumed Cell[0] is
the column that has True or False values.

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
GridViewRow r = e.Row;
if ( r.Cells[0].Text == "True" )
r.Cells[0].Text == "Yes"
else
r.Cells[0].Text == "No"

}

Let me know in case any issues.

-
Vadivel Kumar
http://vadivelk.net
 
V

Vadivel Kumar

Lucky said:
Thanks Pal!
It worked.

Vadivel said:
One way of dealing with this is, use RowDataBound event and use
GridViewRow object to get the currend binded row. Check its
CellCollection to see whether the binding value is true or false and
based on that set the value of the cell.

Please check the below code, which might usefull. I assumed Cell[0] is
the column that has True or False values.

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
GridViewRow r = e.Row;
if ( r.Cells[0].Text == "True" )
r.Cells[0].Text == "Yes"
else
r.Cells[0].Text == "No"

}

Let me know in case any issues.

-
Vadivel Kumar
http://vadivelk.net

Good luck!!

-
Vadivel Kumar
http://vadivelk.net
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top