How do I use a ‘helper function’ to change the column value as Boolean in database to be displayed as Yes/No in Datagrid?

Platform: ASP.NET| Category: DataGrid

<asp:DataGrid id='DataGrid1' runat='server' AutoGenerateColumns='False'>
<Columns>
	<asp:TemplateColumn HeaderText='Status'>
	<ItemTemplate>
		<%#ShowStatus(bool.Parse(DataBinder.Eval(Container.DataItem,'Discontinued').ToString()))%>
	</ItemTemplate>
	</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

VB.NET


protected Function ShowStatus(ByVal someval as boolean)
  If someval = true Then
    ShowStatus = 'Yes'
  Else
    ShowStatus = 'No'
  End If
End Function

C#


protected string ShowStatus(bool  someval)
{
	if (someval == true)
	{
	return 'Yes';
	}
	else
	{
	return 'No';
	}
}

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.