复制代码 代码如下:
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (dr["Depth"].ToString() != "1")
{
dr["ColumnName"] = StringHelper.StringOfChar(Convert.ToInt32(dr["Depth"]) - 1, " ") + "├ " + dr["ColumnName"];
}
}
GridView1.DataSource = ds;
GridView1.DataBind();
复制代码 代码如下:
public static class StringHelper
{
/// <summary>
/// 生成指定长度的字符串,即生成strLong个str字符串
/// </summary>
/// <param>生成的长度</param>
/// <param>以str生成字符串</param>
/// <returns></returns>
public static string StringOfChar(int strLong, string str)
{
string ReturnStr = "";
for (int i = 0; i < strLong; i++)
{
ReturnStr += str;
}
return ReturnStr;
}
/// <summary>
/// 生成日期随机码
/// </summary>
/// <returns></returns>
public static string GetRamCode()
{
#region
return DateTime.Now.ToString("yyyyMMddHHmmssffff");
#endregion
}
}
复制代码 代码如下:
public static DataSet ConvertToDataSet<T>(IList<T> list)
{
if (list == null || list.Count <= 0)
{
return null;
}
DataSet ds = new DataSet();
DataTable dt = new DataTable(typeof(T).Name);
DataColumn column;
DataRow row;
System.Reflection.PropertyInfo[] myPropertyInfo = typeof(T).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
foreach (T t in list)
{
if (t == null)
{
continue;
}
row = dt.NewRow();
for (int i = 0, j = myPropertyInfo.Length; i < j; i++)
{
System.Reflection.PropertyInfo pi = myPropertyInfo[i];
string name = pi.Name;
if (dt.Columns[name] == null)
{
column = new DataColumn(name, pi.PropertyType);
dt.Columns.Add(column);
}
row[name] = pi.GetValue(t, null);
}
dt.Rows.Add(row);
}
ds.Tables.Add(dt);
return ds;
}
复制代码 代码如下:
DataSet ds = ConvertToDataSet(b.ListColumn());
复制代码 代码如下:
BLL b = new BLL();
b.ListColumn();
复制代码 代码如下:
IList<Qzzm.Model.ColumnInfo> list = new List<Qzzm.Model.ColumnInfo>();
foreach (Qzzm.Model.ColumnInfo m in b.ListColumn())
{
if (m.Depth.ToString() != "1")
{
m.ColumnName = StringHelper.StringOfChar(Convert.ToInt32(m.Depth) - 1, " ") + "├ " + m.ColumnName + "<br>";
}
list.Add(m);
}
DataList1.DataSource = list;
DataList1.DataBind();
新闻热点
疑难解答
图片精选