S
studio60podcast
I have an ASPlaceholder and I'm trying to populate with Label
controls from the code behind after a button click, essentially
creating a list of selections. But each time I click the button, it's
replacing the label in the placeholder rather than appending to it.
Is this the way the Placeholder control is supposed to work or is there
a way around this?
protected void btnApplyFilter_Click(object sender, EventArgs e)
{
Label lblAttribute = new Label();
lblAttribute.Text = ddlAttribute.SelectedItem.ToString() + ":";
lblAttribute.CssClass = "textGrey10";
phAttribute.Controls.Add(lblAttribute);
Label lblValue = new Label();
lblValue.Text = ddlValue.SelectedItem.ToString();
lblValue.CssClass = "textGrey10";
phValue.Controls.Add(lblValue);
}
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left">
<asp:Label ID="lblFilterHeader" runat="server" Text="Please select a
report filter" CssClass="textGrey10" />
</td>
</tr>
<tr>
<td align="left">
<aspropDownList ID="ddlAttribute" runat="server"
CssClass="textGrey10"
OnSelectedIndexChanged="ddlAttribute_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem Text="" Value="" />
<asp:ListItem Text="Model" Value="Model" />
<asp:ListItem Text="Name" Value="Name" />
<asp:ListItem Text="Item Type" Value="Item Type" />
<asp:ListItem Text="Vendor" Value="Vendor" />
<asp:ListItem Text="Location" Value="Location" />
<asp:ListItem Text="Department" Value="Department" />
<asp:ListItem Text="Description" Value="Description" />
<asp:ListItem Text="Work Authorization" Value="Work Authorization"
/>
<asp:ListItem Text="PO Date" Value="PO Date" />
<asp:ListItem Text="Warranty Expires" Value="Warranty Expires" />
<asp:ListItem Text="Invoice Number" Value="Invoice Number" />
<asp:ListItem Text="Invoice Date" Value="Invoice Date" />
<asp:ListItem Text="Date Entered" Value="Date Entered" />
<asp:ListItem Text="Serial Number" Value="Serial Number" />
<asp:ListItem Text="Purchase Cost" Value="Purchase Cost" />
<asp:ListItem Text="Active" Value="Active" />
</aspropDownList>
<aspropDownList ID="ddlValue" runat="server" CssClass="textGrey10"
/>
<asp:Button ID="btnApplyFilter" runat="server" CssClass="textGrey10"
Text="Apply Filter" OnClick="btnApplyFilter_Click" />
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" colspan="2">
<asp:Label ID="Label1" runat="server" Text="Current Filters Applied"
CssClass="textGrey10" />
</td>
</tr>
<tr>
<td align="left" width="50%">
<asplaceHolder ID="phAttribute" runat="server" />
</td>
<td align="left" width="50%">
<asplaceHolder ID="phValue" runat="server" />
</td>
</tr>
</table>
controls from the code behind after a button click, essentially
creating a list of selections. But each time I click the button, it's
replacing the label in the placeholder rather than appending to it.
Is this the way the Placeholder control is supposed to work or is there
a way around this?
protected void btnApplyFilter_Click(object sender, EventArgs e)
{
Label lblAttribute = new Label();
lblAttribute.Text = ddlAttribute.SelectedItem.ToString() + ":";
lblAttribute.CssClass = "textGrey10";
phAttribute.Controls.Add(lblAttribute);
Label lblValue = new Label();
lblValue.Text = ddlValue.SelectedItem.ToString();
lblValue.CssClass = "textGrey10";
phValue.Controls.Add(lblValue);
}
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left">
<asp:Label ID="lblFilterHeader" runat="server" Text="Please select a
report filter" CssClass="textGrey10" />
</td>
</tr>
<tr>
<td align="left">
<aspropDownList ID="ddlAttribute" runat="server"
CssClass="textGrey10"
OnSelectedIndexChanged="ddlAttribute_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem Text="" Value="" />
<asp:ListItem Text="Model" Value="Model" />
<asp:ListItem Text="Name" Value="Name" />
<asp:ListItem Text="Item Type" Value="Item Type" />
<asp:ListItem Text="Vendor" Value="Vendor" />
<asp:ListItem Text="Location" Value="Location" />
<asp:ListItem Text="Department" Value="Department" />
<asp:ListItem Text="Description" Value="Description" />
<asp:ListItem Text="Work Authorization" Value="Work Authorization"
/>
<asp:ListItem Text="PO Date" Value="PO Date" />
<asp:ListItem Text="Warranty Expires" Value="Warranty Expires" />
<asp:ListItem Text="Invoice Number" Value="Invoice Number" />
<asp:ListItem Text="Invoice Date" Value="Invoice Date" />
<asp:ListItem Text="Date Entered" Value="Date Entered" />
<asp:ListItem Text="Serial Number" Value="Serial Number" />
<asp:ListItem Text="Purchase Cost" Value="Purchase Cost" />
<asp:ListItem Text="Active" Value="Active" />
</aspropDownList>
<aspropDownList ID="ddlValue" runat="server" CssClass="textGrey10"
/>
<asp:Button ID="btnApplyFilter" runat="server" CssClass="textGrey10"
Text="Apply Filter" OnClick="btnApplyFilter_Click" />
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" colspan="2">
<asp:Label ID="Label1" runat="server" Text="Current Filters Applied"
CssClass="textGrey10" />
</td>
</tr>
<tr>
<td align="left" width="50%">
<asplaceHolder ID="phAttribute" runat="server" />
</td>
<td align="left" width="50%">
<asplaceHolder ID="phValue" runat="server" />
</td>
</tr>
</table>