FineUI 官方论坛
标题:
Grid初始化
[打印本页]
作者:
liluyuan_
时间:
2013-5-17 08:35
标题:
Grid初始化
/// <summary>
/// 初始化Grid控件
/// </summary>
/// <param name="pGD">Grind名</param>
/// <param name="pSql">Sql 语句</param>
/// <param name="sOption">选项,参数</param>
protected void Grid_Iint(FineUI.Grid pGrid, string pSql, string sOption = "")
{
string sKey = "";
string sSql = pSql;
DataTable table = Helper.SqlHelper.GetDataTable(sSql);
foreach (DataColumn col in table.Columns)
{
switch (col.DataType.ToString().ToUpper())
{
case "SYSTEM.BOOLEAN":
FineUI.CheckBoxField bb = new FineUI.CheckBoxField();
bb.DataField = col.ColumnName;
bb.DataToolTipField = col.ColumnName;
bb.HeaderText = Mul_Language(col.ColumnName);
bb.RenderAsStaticField = true;
bb.TextAlign = FineUI.TextAlign.Center;
pGrid.Columns.Add(bb);
break;
case "SYSTEM.DATETIME":
FineUI.BoundField bd;
bd = new FineUI.BoundField();
bd.DataField = col.ColumnName;
bd.DataToolTipField = col.ColumnName;
bd.HeaderText = Mul_Language(col.ColumnName);
bd.DataFormatString = "{0:yyyy-MM-dd}";
bd.TextAlign = FineUI.TextAlign.Right;
pGrid.Columns.Add(bd);
break;
case "SYSTEM.CHAR":
case "SYSTEM.BYTE":
case "SYSTEM.SBYTE":
case "SYSTEM.UINT16":
case "SYSTEM.UINT32":
case "SYSTEM.UINT64":
case "SYSTEM.INT16":
case "SYSTEM.INT32":
case "SYSTEM.INT64":
case "SYSTEM.SINGLE":
case "SYSTEM.DOUBLE":
FineUI.BoundField bn;
bn = new FineUI.BoundField();
bn.DataField = col.ColumnName;
bn.DataToolTipField = col.ColumnName;
bn.HeaderText = Mul_Language(col.ColumnName);
bn.TextAlign = FineUI.TextAlign.Right;
pGrid.Columns.Add(bn);
break;
default:
FineUI.BoundField bf;
bf = new FineUI.BoundField();
bf.DataField = col.ColumnName;
bf.DataToolTipField = col.ColumnName;
bf.HeaderText = Mul_Language(col.ColumnName);
bf.TextAlign = FineUI.TextAlign.Left;
pGrid.Columns.Add(bf);
break;
}
//得到主键
if (sKey == "")
{
sKey = col.ColumnName;
}
else
{
sKey = sKey + "|" + col.ColumnName;
}
}
pGrid.DataKeyNames = sKey.Split('|');
pGrid.DataSource = table;
pGrid.DataBind();
}
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/)
Powered by Discuz! X3.4