Saturday, March 24, 2012

CascadingDropDown, SelectedValue in a bound form

Hey folks,

I don't know if it's been addressed, but I couldn't find the solution.

I need to databind selectedValue of a cascading dropdown. Since TargetProperties cannot be databound using <#% #> syntax, I use DataBinding event handler:

 <form id="form1" runat="server"> <div> <atlas:ScriptManager ID="scriptManager" runat="server" EnablePartialRendering="true" /> <asp:FormView ID="frm1" runat="server" DefaultMode="insert"> <InsertItemTemplate> <asp:Button ID="btnToggle" runat="server" OnClick="btnToggle_OnClick" Text="Toggle dropdown panel" /> <asp:Panel ID="pnlDropdown" runat="server" Visible="false"> <asp:DropDownList ID="ddl1" runat="server" /> <atlasToolkit:CascadingDropDown runat="server" ID="cdd1" OnDataBinding="cdd1_DataBinding"> <atlasToolkit:CascadingDropDownProperties TargetControlID="ddl1" ServiceMethod="GetOptions" PromptText="--Select--" Category="Options" /> </atlasToolkit:CascadingDropDown> </asp:Panel> </InsertItemTemplate> </asp:FormView> </div> </form>

With the following codebehind:

protected void btnToggle_OnClick(object sender, EventArgs args) { Panel pnlDropdown = (Panel) ((Control)sender).Parent.FindControl("pnlDropdown" ); pnlDropdown.Visible = !pnlDropdown.Visible; }protected void cdd1_DataBinding(object sender, EventArgs args) { CascadingDropDown cdd1 = (CascadingDropDown)sender; cdd1.TargetProperties[0].SelectedValue ="1"; } [WebMethod]public CascadingDropDownNameValue[] GetOptions(string knownCategoryValues,string category) { CascadingDropDownNameValue[] cddValues =new CascadingDropDownNameValue[] {new CascadingDropDownNameValue("one","1"),new CascadingDropDownNameValue("two","2") };return cddValues; }

The problem exhibits itself only if the CascadingDropDown is originally hidden.

Obviously, this isn't the production code, but it models the behaviour precisly.

Any way to solve it?

Thanks in advance,

ET

Sorry, I forgot to state the actual problem, thespecified SelectedValue is ignored if the dropdown is not visible at the time of binding. Why?

et_td:

Hey folks,

I don't know if it's been addressed, but I couldn't find the solution.

I need to databind selectedValue of a cascading dropdown. Since TargetProperties cannot be databound using <#% #> syntax, I use DataBinding event handler:

 <form id="form1" runat="server"> <div> <atlas:ScriptManager ID="scriptManager" runat="server" EnablePartialRendering="true" /> <asp:FormView ID="frm1" runat="server" DefaultMode="insert"> <InsertItemTemplate> <asp:Button ID="btnToggle" runat="server" OnClick="btnToggle_OnClick" Text="Toggle dropdown panel" /> <asp:Panel ID="pnlDropdown" runat="server" Visible="false"> <asp:DropDownList ID="ddl1" runat="server" /> <atlasToolkit:CascadingDropDown runat="server" ID="cdd1" OnDataBinding="cdd1_DataBinding"> <atlasToolkit:CascadingDropDownProperties TargetControlID="ddl1" ServiceMethod="GetOptions" PromptText="--Select--" Category="Options" /> </atlasToolkit:CascadingDropDown> </asp:Panel> </InsertItemTemplate> </asp:FormView> </div> </form>

With the following codebehind:

protected void btnToggle_OnClick(object sender, EventArgs args) { Panel pnlDropdown = (Panel) ((Control)sender).Parent.FindControl("pnlDropdown" ); pnlDropdown.Visible = !pnlDropdown.Visible; }protected void cdd1_DataBinding(object sender, EventArgs args) { CascadingDropDown cdd1 = (CascadingDropDown)sender; cdd1.TargetProperties[0].SelectedValue ="1"; } [WebMethod]public CascadingDropDownNameValue[] GetOptions(string knownCategoryValues,string category) { CascadingDropDownNameValue[] cddValues =new CascadingDropDownNameValue[] {new CascadingDropDownNameValue("one","1"),new CascadingDropDownNameValue("two","2") };return cddValues; }

The problem exhibits itself only if the CascadingDropDown is originally hidden.

Obviously, this isn't the production code, but it models the behaviour precisly.

Any way to solve it?

Thanks in advance,

ET


As a workaround, I found that setting SelectedValue in an FormView.ItemCreated event handler works.

Cheers,

ET

No comments:

Post a Comment