This is a migrated thread and some comments may be shown as answers.

Change gridview column value

2 Answers 444 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Grant
Top achievements
Rank 1
Grant asked on 25 Feb 2014, 10:08 AM
I have databinded my gridview  from a particular linq statement which populates certain values from a table.

I need to show a different name when the gridview populates

for eg. instead of saying true(which it says in the database ) I need it to say Active.

I cannot change the database.

        protected void rgUsers_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.Cells[0].Text == "false") 
                { 
                    e.Row.Cells[0].Text = "Inactive"; 
                }
                else
                    if (e.Row.Cells[0].Text == "true")
                    {
                        e.Row.Cells[0].Text = "Active";
                    }
            }
        }
    }
}

2 Answers, 1 is accepted

Sort by
0
Grant
Top achievements
Rank 1
answered on 25 Feb 2014, 10:52 AM
A friend firgured it out.

    protected void rgUsers_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = (GridDataItem)e.Item;
                LinkButton btn1 = (LinkButton)dataItem["btnChange"].Controls[0];

                TableCell cell = (TableCell)dataItem["Active"];
                if (cell.Text == "True")
                {
                    cell.Text = "Active";
                    cell.ForeColor = Color.Green;
                }
                else
                {
                    cell.Text = "Inactive";
                    cell.ForeColor = Color.Red;
                }
            }

        }
0
Accepted
Shinu
Top achievements
Rank 2
answered on 25 Feb 2014, 10:54 AM
Hi Grant,

Please try the following code snippet to set the text value.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
   if (e.Item is GridDataItem)
  {
    GridDataItem item = (GridDataItem)e.Item;
    if (item["ColumnUniqueName"].Text == "True")
    {
        item["ColumnUniqueName"].Text = "Active";
    }
    else  if (item["ColumnUniqueName"].Text == "False")
    {
        item["ColumnUniqueName"].Text = "InActive";
    }
  }
}

Thanks,
Shinu
Tags
Grid
Asked by
Grant
Top achievements
Rank 1
Answers by
Grant
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or