public void LoadColumn()
{
BoundField nameColumn = new BoundField();
nameColumn.DataField = "NAME";
nameColumn.HeaderText = "Name";
gvTitle0.Columns.Add(nameColumn);
nameColumn = new BoundField();
nameColumn.DataField = "EMPLID";
nameColumn.HeaderText = "Emplid";
gvTitle0.Columns.Add(nameColumn);
OracleConnection con = null;
OracleDataReader dtr = null;
con = Util.openConn();
try
{
string sql = string.Empty;
sql = "SELECT A.PORTION , A.DEPT_ID FROM PRO_COST A WHERE A.DEPT_ID = '" + drpDept.SelectedValue.ToString() + "'";
Log.Write("LoadColumn sql: " + sql);
if (con != null)
{
OracleCommand cmd = con.CreateCommand();
cmd = new OracleCommand(sql, con);
cmd.CommandType = CommandType.Text;
dtr = cmd.ExecuteReader();
ColumnID = 1;
if (dtr.HasRows)
{
while (dtr.Read())
{
TemplateField TmpCol = new TemplateField();
TmpCol.HeaderText = dtr["PORTION"].ToString();
gvTitle0.Columns.Add(TmpCol);
TmpCol.ItemTemplate = new TemplateHandler();
}
}
dtr.Dispose();
dtr.Close();
}
con.Dispose();
con.Close();
}
catch (Exception ex)
{
con.Dispose();
con.Close();
Log.Write("Error LoadColumn: " + ex.Message.ToString() + "\n" + ex.StackTrace);
}
}
public class TemplateHandler : ITemplate
{
void ITemplate.InstantiateIn(Control container)
{
TextBox cmd = new TextBox();
cmd.ID = "gvs" + ColumnID.ToString();
Log.Write("ColumnID: " + cmd.ID);
cmd.Text = "0";
container.Controls.Add(cmd);
ColumnID++;
}
}
|