Saturday, March 24, 2012

DropDownLists in 2 separate updatepanels only work once, then dont.

Hey, i have 2 dropdownlists, both databound to my sql server, the first one simply selects anything from the "catagories" database. Autopostback is enabled. The next one is a select to the subcatagories database, with an inner join to catagories on the catagory_id column..

The idea here was to make an ajax enabled cascading databound dropdownlist, and it DOES work... but only once. i tried making the trigger the indexChanged event of the 1st dropdown list, but i have the same results. If i change catagories more than once, i will not get a subcatagory change..

Any ideas?

So not sure why DropDownList1 is in an UpdatePanel, but DropDownList2 is the issue here eh and is in a panel, and has a dependant control, being the first drop down list.

So the second one, add a Trigger like this;

<asp:AsyncPostbackTriggerControlID="DropDownList1"EventName="SelectedIndexChanged"/>

Is that any help? Post a snippet of your page here.

Cheers,

Steve


You should use the Cascading Dropdown of Ajax Control Toolkit, it is specially developed for this purpose. Checkout the live demo of it:
http://www.asp.net/AJAX/Control-Toolkit/Live/CascadingDropDown/CascadingDropDown.aspx


It says AsyncPostbackTrigger was a unknown element... Here's my code:

Catagory:<BR /><asp:DropDownList id="DropDownList1" runat="server" DataValueField="Catagory_ID" DataTextField="Catagory" DataSourceID="SqlDataSource2" AutoPostBack="True"></asp:DropDownList><asp:UpdatePanel id="UpdatePanel1" runat="server" >
<contenttemplate>
SubCatagory:<BR /><asp:DropDownList id="ddlSubCat" runat="server" DataValueField="SubCatagory_ID" DataTextField="SubCatagory" DataSourceID="ddlsubCatagory"></asp:DropDownList>

<asp:SqlDataSource id="SqlDataSource2" runat="server" SelectCommand="SELECT [Catagory], [Catagory_ID] FROM [db_Catagories]" ConnectionString="<%$ ConnectionStrings:floofieConnectionString %>"></asp:SqlDataSource><BR /><asp:SqlDataSource id="ddlsubCatagory" runat="server" SelectCommand="SELECT db_SubCatagories.SubCatagory, db_SubCatagories.SubCatagory_ID FROM db_Catagories INNER JOIN db_SubCatagories ON db_Catagories.Catagory_ID = db_SubCatagories.Catagory_ID WHERE (db_Catagories.Catagory_ID = @.catid)" ConnectionString="<%$ ConnectionStrings:floofieConnectionString %>"><SelectParameters>

<asp:ControlParameter PropertyName="SelectedValue" Name="catid" ControlID="DropDownList1"></asp:ControlParameter>
</SelectParameters>
</asp:SqlDataSource>
</contenttemplate>


KaziManzurRashid:

You should use the Cascading Dropdown of Ajax Control Toolkit, it is specially developed for this purpose. Checkout the live demo of it:
http://www.asp.net/AJAX/Control-Toolkit/Live/CascadingDropDown/CascadingDropDown.aspx

That looks really nice, is there any way of getting the web service code for vb.net?


Can you post the complete markup of UpdatePanel. If any of your dropdown is outsite the update panel set its AutoPostback=true and create AsyncPostbackTrigger in Update Panel which points to that dropdownlist.


KaziManzurRashid:

Can you post the complete markup of UpdatePanel. If any of your dropdown is outsite the update panel set its AutoPostback=true and create AsyncPostbackTrigger in Update Panel which points to that dropdownlist.

Sorry bout that, thought i had it all.

Catagory:<BR /><asp:DropDownList id="DropDownList1" runat="server" DataValueField="Catagory_ID" DataTextField="Catagory" DataSourceID="SqlDataSource2" AutoPostBack="True"></asp:DropDownList><asp:UpdatePanel id="UpdatePanel1" runat="server"> <contenttemplate>SubCatagory:<BR /><asp:DropDownList id="ddlSubCat" runat="server" DataValueField="SubCatagory_ID" DataTextField="SubCatagory" DataSourceID="ddlsubCatagory"></asp:DropDownList> <BR /><asp:SqlDataSource id="SqlDataSource2" runat="server" SelectCommand="SELECT [Catagory], [Catagory_ID] FROM [db_Catagories]" ConnectionString="<%$ ConnectionStrings:floofieConnectionString%>"></asp:SqlDataSource><BR /><asp:SqlDataSource id="ddlsubCatagory" runat="server" SelectCommand="SELECT db_SubCatagories.SubCatagory, db_SubCatagories.SubCatagory_ID FROM db_Catagories INNER JOIN db_SubCatagories ON db_Catagories.Catagory_ID = db_SubCatagories.Catagory_ID WHERE (db_Catagories.Catagory_ID = @.catid)" ConnectionString="<%$ ConnectionStrings:floofieConnectionString%>"><SelectParameters><asp:ControlParameter PropertyName="SelectedValue" Name="catid" ControlID="DropDownList1"></asp:ControlParameter></SelectParameters></asp:SqlDataSource></contenttemplate> <triggers><asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged"></asp:AsyncPostBackTrigger></triggers> </asp:UpdatePanel>

I acctually fixed it... the problem was, there was 3 other updatepanels, and they all need to be set to conditional.

I cant beleive i didnt see that in the first place.

No comments:

Post a Comment