views:

320

answers:

1

Hi....

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

+1  A: 

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";
        }
    }

}
JBrooks