1

如果存在错误键,我访问 rowDataBound 上 DataColumn 的扩展属性并应用某个类和工具提示的最佳方法是什么?

protected void gridView_rowDataBound(object sender, GridViewRowEventArgs e)
{
    switch (e.Row.RowType)
    {
        case DataControlRowType.Header:
            ((DataRow)e.Row.DataItem)...
            break;
        case DataControlRowType.DataRow:

            break;
    }
}

这是我在被卡住之前得到的。我注意到我的 DataRow 演员表没有对 DataColumn 的引用。

4

2 回答 2

0

Well, you could extract out a method to do this for you and call it from all of your grid RowDataBound events. You could put this in a grid utilities class.

public void ShowExtendedProperties(GridViewRow row, DataTable table)
{
switch (row.RowType)
    {
        case DataControlRowType.Header:
            foreach (DataColumn col in table.Columns)
            {
                if (col.ExtendedProperties["error"] != null)
                {
                    row.Cells[col.Ordinal].CssClass = "error-cell";
                    row.Cells[col.Ordinal].ToolTip = col.ExtendedProperties["error"].ToString();
                }
            }                 
            break;
        case DataControlRowType.DataRow:
            //I assume you have logic here, or other case statements?
            break;
    }
}
于 2010-12-02T02:54:04.063 回答
0

以下是我想出的,但遗憾的是,它仅与一个 DataTable 紧密耦合。有没有办法在多个数据表中使用?我真的不想接受我自己蹩脚的答案。

protected void gridView_rowDataBound(object sender, GridViewRowEventArgs e)
{
    switch (e.Row.RowType)
    {
        case DataControlRowType.Header:
            foreach (DataColumn col in myDataTable.Columns)
            {
                if (col.ExtendedProperties["error"] != null)
                {
                    e.Row.Cells[col.Ordinal].CssClass = "error-cell";
                    e.Row.Cells[col.Ordinal].ToolTip = col.ExtendedProperties["error"].ToString();
                }
            }                 
            break;
        case DataControlRowType.DataRow:

            break;
    }
}
于 2010-11-04T12:15:54.307 回答