Conditional output in cell based on row data in Gridview's RowDataBound event

后端 未结 3 350
后悔当初
后悔当初 2021-01-12 22:45

i have a bit value (Black) i want to display its status in gridview as if its true, the row display \"Yes\", otherwise the row display \"No\", this is my code, but the resul

3条回答
  •  清酒与你
    2021-01-12 23:40

    Do you need to iterate through a DataTable dt on each RowDatabound ?

    If you do not need this could you try:

    protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
    
                    Boolean bitBlack = Convert.ToBoolean(e.Row.Cells[7].Text);
                    if (bitBlack)
                    {
                        e.Row.Cells[7].Text = "Yes";
                    }
                    else
                    {
                        e.Row.Cells[7].Text = "No";
                    }
    
            }
        }
    

提交回复
热议问题