How to check the status (True / False) as a grid in the rowdatabound event?

I have a table with three columns (ProdID, ProdName, Status). I collect this in a dataSet and bind it to my gridview. I have a very simple and simple rowdatabound event like this:

 protected void gvProducts_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[2].Text == "False")
            {
                e.Row.BackColor = System.Drawing.Color.PaleVioletRed;
            }
        }
    }

But when I see my third column (Status), it turns into a checkbox, maybe it contains only "True" or "False". Also in my if condition:

if (e.Row.Cells[3].Text == "False")

The text value shows this:

""

Can someone suggest me how I can compare my status with True or False in my if condition.

+3
source share
3 answers

you can try...

if (((CheckBox)e.Row.Cells[3]).Checked == false)

OR, the event is better if you like ..

 if(((CheckBox)e.Row.FindControl("YourCheckboxID")).Checked == false)

:, RowDataBound, , . , ...

DataRow dr = ((DataRowView)e.Item.DataItem).Row;
if (Convert.ToBoolean(dr["Status"]) == false)
+3

, CheckBox:

e.Rows.Cells[3].Controls

:

((CheckBox)e.Rows.Cells[3].Controls[0]).Checked
+1

If the Status column is a set of flags, check to see if the property is a checkmark Checked trueor false.

0
source

Source: https://habr.com/ru/post/1792725/


All Articles