asp.net 如何将html图标插入到datagridview中

o3imoua4  于 12个月前  发布在  .NET
关注(0)|答案(1)|浏览(143)

我正在尝试将html图标放入datagridview行中,以显示文件夹被锁定的时间。下面的代码当前仅在文件夹被锁定时在datagridview行中显示“是”。我想将“是”替换为html图标。

// Creating a new DataTable.
DataTable custTable = new DataTable("folders");
DataColumn dtaColumn;
DataRow myDataRow;

// Create id column
dtaColumn = new DataColumn();
dtaColumn.DataType = typeof(string);
dtaColumn.ColumnName = "Type";
dtaColumn.Caption = "Type";
custTable.Columns.Add(dtaColumn);

dtaColumn = new DataColumn();
dtaColumn.DataType = typeof(String);
dtaColumn.ColumnName = "Description";
dtaColumn.Caption = "Description";
dtaColumn.ReadOnly = false;
dtaColumn.Unique = false;
custTable.Columns.Add(dtaColumn);

dtaColumn = new DataColumn();
dtaColumn.DataType = typeof(String);
dtaColumn.ColumnName = "Size";
dtaColumn.Caption = "Size";
dtaColumn.ReadOnly = false;
dtaColumn.Unique = false;
custTable.Columns.Add(dtaColumn);

dtaColumn = new DataColumn();
dtaColumn.DataType = typeof(String);
dtaColumn.ColumnName = "Locked";
dtaColumn.Caption = "Locked";
dtaColumn.ReadOnly = false;
dtaColumn.Unique = false;
custTable.Columns.Add(dtaColumn);

dtaSet = new DataSet();
dtaSet.Tables.Add(custTable);

string[] subdirectoryEntries = Directory.GetDirectories(Server.MapPath(pathToFollow));

//creating rows
foreach (string folderPath in subdirectoryEntries)
{   
    myDataRow = custTable.NewRow();

    myDataRow["Type"] = "Folder";
    myDataRow["Description"] = Path.GetFileName(folderPath);
    myDataRow["Size"] = "NA";
    
    //checking if folder is locked
    for(int i = 0; i<pathLock.Count; i++)
    {
        if (pathLock[i] == folderPath)
        {
            myDataRow["Locked"] = "Yes"; //Place to insert the icon
        }
    }
    custTable.Rows.Add(myDataRow);
}

字符串
HTML图标的代码

<span class="fa fa-lock"></span>


这就是我当前代码的样子。

wz8daaqr

wz8daaqr1#

使用gridview的rowdatabound事件:

void gridview_rowdatabound(...)
{
    if (e.row.rowtype == datacontrolrowtype.datarow)
    {
        if (e.row.cells[2].text == "Locked")
        {
            e.row.cells[2].text = "<span class='fa fa-lock'></span>";
        }
    }
}

字符串
假设Locked的列索引为2。

相关问题