Search code examples
gridviewdatatablebindboundfield

When Binding a GridView to a DataTable, How can we Change the value displayed by a BoundField


When Binding a GridView to a DataTable, How can we Change the value displayed by a BoundField


Solution

  • One way is like so:

    <asp:CheckBox ID="CheckBox1" runat="server" 
    Checked='<%# (((String)DataBinder.Eval(Container.DataItem, "Status")) == "O")?true:false %>' />
    

    and then you have control in the code behind like:

    protected void gvFiles_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (DataBinder.Eval(e.Row.DataItem, "LastUser").ToString() == "x")
            {
                TextBox txtId = gvFiles.FindControl("txtId") as TextBox;
                txtId.Text = "NA";
            }
        }
    
    }