如果value为true,则更新SQL列

时间:2015-05-07 10:02:51

标签: c# asp.net sql-server

我有一点值(在状态中)我想在gridview中显示它的状态,如果是,行显示"活动"否则行显示"非活动",这是我的代码,但结果显示为True或false。根据{{​​1}}或Active,“操作”列必须显示InactiveDeactivate

Activate

以下是代码隐藏:

ShopNumber  ShopName    Address Website   Status    Action  Settings
2             abc        Kuwait xyz.com     True    Deactivate  Edit
3             def        Kuwait deuuy       False   Activate    Edit
4            Major       Minor  Usra.com    True    Activate    Edit
5             Isys       Kuwait isys.com    False   Activate    Edit
6            Avenues     Kuwait avenues.com False   Activate    Edit

这是ASP代码:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            Boolean bitCheck = Convert.ToBoolean(e.Row.Cells[4].Text);
            if (bitCheck)
            {
                e.Row.Cells[4].Text = "Active";
            }
            else
            {
                e.Row.Cells[4].Text = "Inactive";
            }

        }

1 个答案:

答案 0 :(得分:1)

您正在使用项目模板,而不仅仅是将其绑定到列。因此,您必须投射Label来编辑它Text

Label status = (Label)e.Row.Cells[4].FindControl("Label2");
Label action = (Label)e.Row.Cells[5].FindControl("Label1");

Boolean bitCheck = Convert.ToBoolean(status.Text);
if (bitCheck)
{
    status.Text = "Active";
    action.Text = "Activated";
}
else
{
    status.Text = "Inactive";
    action.Text = "Deactivated";
}