我正在尝试将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>
型
这就是我当前代码的样子。
1条答案
按热度按时间wz8daaqr1#
使用gridview的rowdatabound事件:
字符串
假设
Locked
的列索引为2。