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.
Iftikar HussainPosted Aug 15, 2013, 11:51 PM
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
Jignesh TrivediPosted Aug 15, 2013, 11:26 PM
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.
Hemant SrivastavaPosted Aug 15, 2013, 9:05 AM
Sanjeeb LenkaPosted Aug 15, 2013, 6:15 AM
rajesh yadavPosted Aug 15, 2013, 4:25 AM
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 LenkaPosted Aug 14, 2013, 3:33 PM
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;
}
}
Hemant SrivastavaPosted Aug 14, 2013, 3:04 PM