M
Mark Rae
Hi,
I'm sure I've done this before, but I can't get it to work today...
I'm trying to add a DropDownList into a TableCell and wire up its
SelectedIndexChanged event. I'm adding the dynamic control like this:
mtblCell = new TableCell();
mtblCell.ColumnSpan = 2;
DropDownList cmbShipping = new DropDownList();
cmbShipping.Items.Add(new ListItem("", "0"));
cmbShipping.Items.Add(new ListItem("United Kingdom", "1"));
cmbShipping.Items.Add(new ListItem("European Union", "2"));
cmbShipping.Items.Add(new ListItem("Rest of world", "3"));
cmbShipping.AutoPostBack = true;
cmbShipping.SelectedIndexChanged += new
EventHandler(cmbShipping_SelectedIndexChanged);
mtblCell.Controls.Add(cmbShipping);
mtblRow.Cells.Add(mtblCell);
I've already created the code for the event:
private void cmbShipping_SelectedIndexChanged(object sender, EventArgs e)
{
BindData();
}
It all seems to work well enough inasmuch as the DropDownList certainly does
get created in the TableCell - the resulting HTML looks like this:
<td colspan="2">
<select name="_ctl0" onchange="__doPostBack('_ctl0','')"
language="javascript">
<option value="0"></option>
<option value="1">United Kingdom</option>
<option value="2">European Union</option>
<option value="3">Rest of world</option>
</select>
</td>
When I change the selected index of the DropDownList, it does the postback
as expected. However, the cmbShipping_SelectedIndexChanged event doesn't
fire. I must be missing something totally obvious.
Any assistance gratefully received.
Mark
I'm sure I've done this before, but I can't get it to work today...
I'm trying to add a DropDownList into a TableCell and wire up its
SelectedIndexChanged event. I'm adding the dynamic control like this:
mtblCell = new TableCell();
mtblCell.ColumnSpan = 2;
DropDownList cmbShipping = new DropDownList();
cmbShipping.Items.Add(new ListItem("", "0"));
cmbShipping.Items.Add(new ListItem("United Kingdom", "1"));
cmbShipping.Items.Add(new ListItem("European Union", "2"));
cmbShipping.Items.Add(new ListItem("Rest of world", "3"));
cmbShipping.AutoPostBack = true;
cmbShipping.SelectedIndexChanged += new
EventHandler(cmbShipping_SelectedIndexChanged);
mtblCell.Controls.Add(cmbShipping);
mtblRow.Cells.Add(mtblCell);
I've already created the code for the event:
private void cmbShipping_SelectedIndexChanged(object sender, EventArgs e)
{
BindData();
}
It all seems to work well enough inasmuch as the DropDownList certainly does
get created in the TableCell - the resulting HTML looks like this:
<td colspan="2">
<select name="_ctl0" onchange="__doPostBack('_ctl0','')"
language="javascript">
<option value="0"></option>
<option value="1">United Kingdom</option>
<option value="2">European Union</option>
<option value="3">Rest of world</option>
</select>
</td>
When I change the selected index of the DropDownList, it does the postback
as expected. However, the cmbShipping_SelectedIndexChanged event doesn't
fire. I must be missing something totally obvious.
Any assistance gratefully received.
Mark