Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DataColumn.ExtendedProperties数据到GridView_C#_Gridview_Datatable_Datacolumn_Extended Properties - Fatal编程技术网

C# DataColumn.ExtendedProperties数据到GridView

C# DataColumn.ExtendedProperties数据到GridView,c#,gridview,datatable,datacolumn,extended-properties,C#,Gridview,Datatable,Datacolumn,Extended Properties,如果存在错误键,那么访问rowDataBound上DataColumn的扩展属性并应用特定类和工具提示的最佳方法是什么 protected void gridView_rowDataBound(object sender, GridViewRowEventArgs e) { switch (e.Row.RowType) { case DataControlRowType.Header: ((DataRow)e.Row.DataItem)..

如果存在错误键,那么访问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 cast没有对DataColumn的引用。

下面是我的想法,但遗憾的是,它只与一个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;
    }
}

好的,您可以提取一个方法来为您执行此操作,并从所有网格RowDataBound事件中调用它。您可以将其放在网格实用程序类中

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