Live Chat Icon For mobile
Live Chat Icon

How to enable or disable the button in the DataGrid based on a bit value in the database

Platform: ASP.NET| Category: DataGrid

<asp:DataGrid id='DataGrid1' runat='server'>
<Columns>
<asp:TemplateColumn HeaderText ='Product Information' >
<ItemTemplate >
<asp:Button CommandName='Status' Text ='Status' Runat =server  
	Enabled =<%#CheckStatus(Convert.ToBoolean(DataBinder.Eval(Container.DataItem,'Discontinued')))%> ID='Button1' >
</asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

VB.NET


Protected Function CheckStatus(ByVal prdStatus As Boolean) As Boolean
	If prdStatus = False Then
		Return True
	Else
		Return False
	End If
End Function

C#


protected bool CheckStatus(bool prdStatus)
{
	//If the Discontinued field is '0'
	if (prdStatus==false)
	{
		return true;
	}
	//If the Discontinued field is '1'
	else
	{
		return false;
	}
}

Share with

Share on twitter
Share on facebook
Share on linkedin