Wednesday, July 15, 2009

dynamically creating controls based on "db" values

int testId = Convert.ToInt32(uxTestId.Value);
string accessionNo = uxHidAccessNo.Value;
IList ListData = new ArrayList();
IList valueData = new ArrayList();
ListData = _lmsUI.getDataReqAtSamCollectionDetailsListForResultPopup(testId);
valueData = _lmsUI.getDataReqAtSampleCollectionValueListRorResultPopup(accessionNo);
int i = 0;
foreach (DataRequiredAtSampleCollection samData in ListData)
{
string[] sd = null;
Label l1 = new Label();
l1.ID = "uxLbl1" + i;
l1.Text = samData.ParameterName;
Label l2 = new Label();
l2.Text = samData.ParameterId.ToString();
l2.Visible = false;
TextBox t1 = new TextBox();
t1.ID = "uxValueTxt" + i;
if (samData.DataType == "LargeText")
{
t1.TextMode = TextBoxMode.MultiLine;
t1.Width = 200;
t1.Height = 50;
t1.Font.Size = 8;
}
if (samData.DataType == "Text" samData.DataType == "Number" samData.DataType == "LargeText")
{
foreach (DataRequiredAtSampleCollection value in valueData)
{
if (samData.ParameterId == value.ParameterId)
{
t1.Text = value.Value;
}
}
}
if (samData.DataType == "Number")
{
t1.Attributes.Add("OnKeyPress", "showValues();");
}
DropDownList drop = new DropDownList();
drop.Width = 155;
drop.ID = "uxValueDdl" + i;
if (samData.Value != "")
{
sd = samData.Value.Split(',');
int k = 0;
foreach (string s in sd)
{
if (s != "")
{
drop.Items.Insert(k, s);
k++;
}
}
drop.Items.Insert(0, "");
foreach (DataRequiredAtSampleCollection value in valueData)
{
if (samData.ParameterId == value.ParameterId)
{
drop.SelectedItem.Text = value.Value.Trim();
}
}
}
TableCell tcell1 = new TableCell();
tcell1.Controls.Add(l1);
TableCell tcell2 = new TableCell();
tcell2.Controls.Add(l2);
TableCell tcell3 = new TableCell();
if (samData.DataType != "List")
{
tcell3.Controls.Add(t1);
}
else
{
tcell3.Controls.Add(drop);
}
TableRow tr1 = new TableRow();
tr1.Cells.Add(tcell1);
tr1.Cells.Add(tcell2);
tr1.Cells.Add(tcell3);
uxDynamicTb.Controls.Add(tr1);
uxSaveBtn.Visible = true;
uxCancelBtn.Visible = true;
i++;
}

No comments:

Post a Comment