Reputation: 1
I am working in ASP.Net, I am saving the status field in Database as true or false. Now, I want to display the true or false as Active or Inactive in the front end in GridView. How to display the data in Gridview.
Thanks in advance.
Upvotes: 0
Views: 706
Reputation: 685
If you are using template field then you can create server side function and call on Eval like below
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblstatus" runat="server" Text='<%# GetStatusText(Eval("status")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
public string GetStatusText(string strIsActive)
{
bool val = Boolean.Parse(strIsActive);
if(val)
{
return "Active";
}
else
{
return "Inactive";
}
}
Upvotes: 0
Reputation: 2341
If you know the cell location of which you want to filter data, you could also do this in the gridviews RowDataBound event.
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[2].Text == "1")
e.Row.Cells[2].Text = "True";
else
e.Row.Cells[2].Text = "False";
}
}
This is what I used to find and replace text in a gridview.
Upvotes: 0
Reputation: 33183
The alternative is to use your datagrid's RowDataBound event to convert what is it to the strings active / inactive:
Protected Sub gvRequests_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvRequests.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim lbl As Label = CType(e.Row.FindControl("lblStatus"), Label)
If lbl.Text="1" then
lbl.Text="Active"
else
lbl.Text="Inactive"
end if
end if
end sub
Upvotes: 3
Reputation: 1444
use checkbox column to show the status field. ( set that column to disable )
Upvotes: 0
Reputation: 888185
If you're asking how to change true
and false
to Active
and Inactive
, you could use a CASE
statement in your SQL query, like this:
SELECT CASE Status WHEN 1 THEN 'Active' WHEN 0 THEN 'Inactive' END FROM Something
For a more specific answer, please post more details.
Upvotes: 1