datagrid question

  • Thread starter Thread starter Balint Toth
  • Start date Start date
B

Balint Toth

Hi all,

I bind an sql table to a datagrid. The table has a status column, this is
smallint. I would like to write "Busy" to the datagrid, if status=0, "Done",
if status=1, and "error" if status=2 and not 1,2,3.

How can I solve this problem?

Thank you very much in advance!

Best regards,
Bálint Tóth
 
If you're using a MS SQL Server, you could write an SQL statement to
retrieve the data from the table and use the SELECT CASE function to
translate the 1,2,3's into "Busy", "Done", "Error".

select
case status
when '0' then 'Busy'
when '1' then 'Done'
when '3' then 'Done'
end as status
from
someTable
 
Thank you for your reply.

The second solution would be good (I change the status on the fly), but
unfortuntaly I am using winforms datagrid. How can I solve the problem in
case of a winforms datagrid?

Thanks in advance!

Regards,
Bálint Tóth

"Bin Song, MCP" <[email protected]> az alábbiakat írta a
következo üzenetben
Hi,

Two way to do this:
One is change the SQL statement that graps the data:
Select StatusName = Case Status When 0 Then 'Busy' When 1 Then 'Done' When
2 Then 'Error' End From YourTable
Then bind StatusName to the grid.

Another solution is Binding dynamically:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
 
Back
Top