I'm creating a custom drop down list with AJAX dropdownextender. Inside my drop panel I have linkbuttons for my options.
<asp:Label ID="ddl_Remit" runat="server" Text="Select remit address."
Style="display: block; width: 300px; padding:2px; padding-right: 50px; font-family: Tahoma; font-size: 11px;" />
<asp:Panel ID="DropPanel" runat="server" CssClass="ContextMenuPanel" Style="display :none; visibility: hidden;">
<asp:LinkButton runat="server" ID="Option1z" Text="451 Stinky Place Drive <br/>North Nowhere, Nebraska 20503-2343 " OnClick="OnSelect" CssClass="ContextMenuItem" />
<asp:LinkButton runat="server" ID="Option2z" Text="451 Stinky Place Drive <br/>North Nowhere, Nebraska 20503-2343 " OnClick="OnSelect" CssClass="ContextMenuItem" />
<asp:LinkButton runat="server" ID="Option3z" Text="451 Stinky Place Drive <br/>North Nowhere, Nebraska 20503-2343 " OnClick="OnSelect" CssClass="ContextMenuItem" />-->
</asp:Panel>
<ajaxToolkit:DropDownExtender runat="server" ID="DDE"
TargetControlID="ddl_Remit"
DropDownControlID="DropPanel" />
And this works well. Now what I have to do is dynamically fill this dropdownlist. Here is my best attempt:
private void fillRemitDDL()
{
//LinkButton Text="451 Stinky Place Drive <br/>North Nowhere, Nebraska 20503-2343 " OnClick="OnSelect" CssClass="ContextMenuItem"
DAL_ScanlineTableAdapters.SL_GetRemitByScanlineIDTableAdapter ta = new DAL_ScanlineTableAdapters.SL_GetRemitByScanlineIDTableAdapter();
DataTable dt = (DataTable)ta.GetData(int.Parse(this.SLID));
if (dt.Rows.Count > 0)
{
Panel ddl = this.FindControl("DropPanel") as Panel;
ddl.Controls.Clear();
for (int x = 0; x < dt.Rows.Count; x++)
{
LinkButton lb = new LinkButton();
lb.Text = dt.Rows[x]["Remit3"].ToString().Trim() + "<br />" + dt.Rows[x]["Remit4"].ToString().Trim() + "<br />" + dt.Rows[x]["RemitZip"].ToString().Trim();
lb.CssClass = "ContextMenuItem";
lb.Attributes.Add("onclick", "setDDL(" + lb.Text + ")");
ddl.Controls.Add(lb);
}
}
}
My problem is that I cannot get the event to run script! I've tried the above code as well as replacing "lb.Attributes.Add("onclick", "setDDL(" + lb.Text + ")");" with "lb.Click += new EventHandler(OnSelect);" and also "lb.OnClientClick = "setDDL(" + lb.Text + ")");" I'm testing the the branches with Alerts on client-side and getting nothing.
Edit: I would like to try adding the generic anchor but I think I can add the element to an asp.net control. Nor can I access a client-side div from server code to add it that way. I'm going to have to use some sort of control with an event. My setDLL function goes as follows:
function setDDL(var)
{
alert(var);
document.getElementById('ctl00_ContentPlaceHolder1_Scanline1_ddl_Remit').innerText = var;
}
Also I just took out the string variable in the function call (i.e. from lb.Attributes.Add("onclick", "setDDL(" + lb.Text + ")"); to lb.Attributes.Add("onclick", "setDDL()");