views:

47

answers:

4

Hi, 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.

Can anyone know please reply me..

Thanks in advance.

+1  A: 

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.

SLaks
you are right !!need more details.
Pragnesh Patel
A: 

use checkbox column to show the status field. ( set that column to disable )

Pragnesh Patel
This is visually nice as it can save space however a lot of admin / assistants like to clearly see a row as inactive / active rather then remember what a check box means. Another way to handle this is to color the row light green if it is active / light red if it is inactive.
JonH
Yes you can set the row color in databound event. That is more userfriendly. (i.e Green-Active, Red-InActive
Pragnesh Patel
+3  A: 

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
JonH
A: 

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.

Idealflip