Dec 19, 2008, 5:16 PM
Problem with dynamic controls creation
Hi everybody, maybe you can help me with this.
What i'm trying to do is to create control dynamically depending of the type of the data stored in a list (datatable). i.e: Numeric -> NumericField, Text ->Textfield and so on.
I'm creating the controls successfully, but the problem is when i try to specify the value the control has to be started with. Something a little weird is that it works with the checkboxes and datefields, but not with the others.
I'm about to get crazy, please help me with this maybe i'm doing something wrong.
Here's the code
IMPORTANT
------------------
By the way, i guess maybe there's something wrong with the user accounts in your site, cause when i logged in first (today) i was registered under vladimir's account although it never happened before, I even made some screenshots of that so you can see it too (take a look to the attachment).
Thanks in advance!
-afhi-
What i'm trying to do is to create control dynamically depending of the type of the data stored in a list (datatable). i.e: Numeric -> NumericField, Text ->Textfield and so on.
I'm creating the controls successfully, but the problem is when i try to specify the value the control has to be started with. Something a little weird is that it works with the checkboxes and datefields, but not with the others.
I'm about to get crazy, please help me with this maybe i'm doing something wrong.
Here's the code
<%@ Page Language="C#" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e) {
crearControles();
}
protected void crearControles()
{
string[,] strValores = { { "TextField", "20" }, { "Checkbox", "True" }, { "DateField", "20/12/2008" }, { "NumberField", "10" } };
for (int i = 0; i < 4; i++)
{
switch (strValores[i,0])
{
case "NumberField":
NumberField num = new NumberField();
num.ID = "ctrl" + i;
num.Width = Unit.Pixel(200);
num.FieldLabel= strValores[i,0];
num.Text = strValores[i,1];
agregarControlesAtribTipoEP(num);
break;
case "TextField":
TextField txt = new TextField();
txt.ID = "ctrl" + i;
txt.Width = Unit.Pixel(200);
txt.FieldLabel= strValores[i,0];
txt.Text = strValores[i,1];
agregarControlesAtribTipoEP(txt);
break;
case "Checkbox":
Checkbox chk = new Checkbox();
chk.ID = "ctrl" + i;
chk.FieldLabel= strValores[i,0];
chk.Checked = Convert.ToBoolean(strValores[i,1]);
agregarControlesAtribTipoEP(chk);
break;
case "DateField":
DateField dtf = new DateField();
dtf.ID = "ctrl" + i;
dtf.FieldLabel= strValores[i,0];
dtf.SelectedDate = Convert.ToDateTime(strValores[i,1]);
agregarControlesAtribTipoEP(dtf);
break;
default:
TextField ctrl = new TextField();
ctrl.ID = "ctrl" + i;
ctrl.Width = Unit.Pixel(200);
ctrl.FieldLabel= strValores[i,0];
ctrl.Text = strValores[i,1];
agregarControlesAtribTipoEP(ctrl);
break;
}
}
}
protected void agregarControlesAtribTipoEP(Field ctrl)
{
Anchor anc = new Anchor();
anc.Items.Add(ctrl);
FormLayout1.Anchors.Add(anc);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server">
</ext:ScriptManager>
<ext:Panel ID="Panel1" runat="server" Height="300" Width="400" Title="Dynamic controls" Frame="true">
<Content>
<ext:FormLayout ID="FormLayout1" runat="server">
</ext:FormLayout>
</Content>
</ext:Panel>
</form>
</body>
</html>
IMPORTANT
------------------
By the way, i guess maybe there's something wrong with the user accounts in your site, cause when i logged in first (today) i was registered under vladimir's account although it never happened before, I even made some screenshots of that so you can see it too (take a look to the attachment).
Thanks in advance!
-afhi-