hi,
i am using vs 2005, sqlserver 2005
I have a column tinyint having 1,0 int it .
1) i want to show true and false in gridveiw.
2) i want to show true and false in data table rather than 0 or 1 or convert the type tinyin to to bool in datatable.please tel me how i can accomplish the task.
yours sincerly.

Hemant SrivastavaRank #581 · 4.2K reputationPosted Aug 14, 2013, 11:04 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 14, 2013, 11:33 AM EDT
you can do it in grid bind in item template like this in asp.net
if you want in windows form try this:
You can use the CellFormatting event of the DataGridView, e.g.:
void dataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
var grid = (DataGridView)sender;
if (grid.Columns[e.ColumnIndex].Name == "Status")
{
e.Value = (bool)e.Value ? "True" : "False";
e.FormattingApplied = true;
}
}
rajesh yadav3 reputationPosted Aug 15, 2013, 12:25 AM EDT
i do not want to change the col type in sqlserver nor do i want to change the query.
only thing i can do is do some changes, conversion in page (PL)
in page i have datatable of .net and grid view
so please tel me some means of changing the type in datatable and showing true and false in gridview keeping the type bool.
yours sincerely
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 15, 2013, 2:15 AM EDT
Hemant SrivastavaRank #581 · 4.2K reputationPosted Aug 15, 2013, 5:05 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Aug 15, 2013, 7:26 PM EDT
hi,
You can made change your query, that show true false it self.
Like
Select *, Case Status when 0 than 'False' else 'True' end as Status From TableA
hope this will help you.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 7:51 PM EDT
If you are sure that your column value will be always contain either 0 or 1, then I suggest first change the datatype from tinyint to bit. Reason, in tinyint datatype it can store other than 0 and 1, but not in bit data type.
Then in your grid just use like this
if you want also in your datatable then, while reading the data use convert
LblTempText=Convert.ToBoolean(reader["YourColumnName"])
Regards,
Iftikar