【问题标题】:When Binding a GridView to a DataTable, How can we Change the value displayed by a BoundField将GridView绑定到DataTable时,如何改变BoundField显示的值
【发布时间】:2009-07-15 11:45:11
【问题描述】:

GridView绑定DataTable时,如何改变BoundField显示的值

【问题讨论】:

  • 找到了!必须使用 RowDataBound 事件处理程序,然后检查 RowType ....

标签: gridview datatable bind boundfield


【解决方案1】:

一种方式是这样的:

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

然后你可以控制后面的代码:

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

}

【讨论】:

    猜你喜欢
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 2013-12-16
    • 2015-12-23
    • 1970-01-01
    • 1970-01-01
    • 2010-10-30
    • 2014-12-22
    相关资源
    最近更新 更多