Sql database has true/false but in gridview it should be Active/Inactive
I had database with a column true/false but in grid view I need to display Active in green color and Inactive in gray color. I tried to directly bind the database which is displaying true/false in drop down list in Grid view.Aspx code:
<asp:TemplateField HeaderText="Activity">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Inactive") %>' Visible="false" />
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
Code behind : Binding database code
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Find the DropDownList in the Row
DropDownList DropDownList1 = (e.Row.FindControl("DropDownList1") as DropDownList);
DropDownList1.DataSource = GetData("Select DISTINCT Inactive from dbo.tblTBT_Depts");
DropDownList1.DataTextField = "Inactive";
DropDownList1.DataValueField = "Inactive";
DropDownList1.DataBind();
//Select the Inactive of Dept in DropDownList
string inactive = (e.Row.FindControl("Label1") as Label).Text;
DropDownList1.Items.FindByValue(inactive).Selected = true;
}
}
Can I now how to change the code?