Wednesday, March 28, 2012

Linking two DropDowns via Atlas?

I have looked at the Atlas controls (January 2006 Release)

What i would like to know is, say i make a dropdown, place it in a
update panel, then link it all up to some datasource, add a trigger to
the page to populate the dropdown, e.g. a button (i get this going
np.)

Now what i would like to do is add a second dropdown and have it
update when i make a selection from the first dropdown, this i can not
get to work.

In the Atlas controls smart tag to add the triggers i only get to see
controls on the page which are not located within a updatepanel,

So i tried to just write then trigger manually, this produced no
visible error on the page, but the second dropdown is not populating
either?

Is this along the lines you are looking to do?

<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />

<atlas:UpdatePanel runat="server" ID="UpdatePanel1" Mode="Conditional" >
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="foo" Value="foo" />
<asp:ListItem Text="bar" Value="bar" />
</asp:DropDownList>
</ContentTemplate>
</atlas:UpdatePanel>
<hr />
<atlas:UpdatePanel runat="server" ID="Computer" Mode="Conditional">
<Triggers>
<atlas:ControlEventTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</ContentTemplate>
</atlas:UpdatePanel>


No thats it exactly, but thank youBig Smile [:D]

Did you have to manually type the second trigger (to populate dropdown2)?

What i was wondering was,

Say you had a button, when pressed, it fired a trigger to populate the first Dropdown1 (Foo, Bar)

Then I wanted to be able to make a selection from the Dropdown1 and then get data to populate Dropdown2,

by running a SQL Query which took the selected item from Dropdown1 as a param.


Made a Typo sorry

I said in last post

No thats it exactly, but thank you

I mean

No thats not exactly it, but thank youWink [;)]


Sad [:(] Example, this does not update the second "Dropdown2", both controls are contained in the 1 UpdatePanel

<atlas:UpdatePanel runat="server" ID="UpdatePanel1" Mode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem Text="foo" Value="foo" />
<asp:ListItem Text="bar" Value="bar" />
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger ControlID="Button1" EventName="Click" />
<atlas:ControlEventTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</atlas:UpdatePanel>

Smile [:)] This example does, but you need to have 2 UpdatePanels

<atlas:UpdatePanel runat="server" ID="UpdatePanel1" Mode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem Text="foo" Value="foo" />
<asp:ListItem Text="bar" Value="bar" />
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</atlas:UpdatePanel>
<hr />
<atlas:UpdatePanel runat="server" ID="Computer" Mode="Conditional">
<Triggers>
<atlas:ControlEventTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</ContentTemplate>
</atlas:UpdatePanel>


in this example i have the script manager and updateprogress atlas controls on a master page, thus i gane share them around between different pages in the test site this has the button control out site which triggers the population of the dropdown1 control, then making a selection from the dropdown1 populates dropdown2 This is what i wanted to do in the first post i made.

Client side code:

<%@.PageLanguage="VB"MasterPageFile="~/MasterPage.master"AutoEventWireup="false"CodeFile="Default.aspx.vb"Inherits="_Default"title="Untitled Page" %>

<asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">

<div>

<asp:ButtonID="Button1"runat="server"Text="Button"/>

<atlas:UpdatePanelrunat="server"ID="UpdatePanel1"Mode="Conditional">

<ContentTemplate>

Dropdown 1

<asp:DropDownListID="DropDownList1"runat="server"OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"

AutoPostBack="True">

<asp:ListItemText="foo"Value="foo"/>

<asp:ListItemText="bar"Value="bar"/>

</asp:DropDownList><br/>

Dropdown 2

<asp:DropDownListID="DropDownList2"runat="server">

</asp:DropDownList>

</ContentTemplate>

<Triggers>

<atlas:ControlEventTriggerControlID="Button1"EventName="Click"/>

<atlas:ControlEventTriggerControlID="DropDownList1"EventName="SelectedIndexChanged"/>

</Triggers>

</atlas:UpdatePanel>

</div>

</asp:Content>

Server Side code:

PartialClass _Default

Inherits System.Web.UI.Page

Dim dsAs Data.DataSet

Dim obsAs Data.DataTable

Dim defAs Data.DataTable

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

ds =New Data.DataSet

obs =New Data.DataTable

def =New Data.DataTable

ds.ReadXml("url to my xml datasopurce here")

def = ds.Tables("data-def")

obs = ds.Tables("obs")

EndSub

ProtectedSub DropDownList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)

Dim xmldocAsNew System.Xml.XmlDocument

xmldoc.LoadXml(ds.GetXml)

Dim obsAs System.Xml.XmlNodeList = xmldoc.SelectNodes("weather-observations/product/group/obs")

Dim xmlEAs System.Xml.XmlElement

ForEach xmlEIn obs

If xmlE.Attributes.Item(4).Value =Me.DropDownList1.SelectedItem.TextThen

Me.DropDownList2.Items.Clear()

Dim xmlEnumeratorAs IEnumerator

xmlEnumerator = xmlE.ChildNodes.GetEnumerator()

xmlEnumerator.Reset()

While xmlEnumerator.MoveNext

Dim eleAs System.Xml.XmlElement

ele = xmlEnumerator.Current

Me.DropDownList2.Items.Add(ele.Attributes.Item(0).Value &" : " & ele.FirstChild.Value)

EndWhile

EndIf

Next

EndSub

ProtectedSub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.Click

Me.DropDownList1.DataSource = obs

Me.DropDownList1.DataTextField ="station"

Me.DropDownList1.DataBind()

EndSub

EndClass


In the latest rev of Atlas, controls within the UpdatePanel should not require an explicit trigger as this is implied. If you want the UpdatePanel to refresh based on controls outside the UpdatePanel then the trigger is required. This therefore means that controls outside the UpdatePanel are traditionally post-back controls unless wired to triggers.The simplified example (#1) therefore should be OK without the DropDownList trigger. The Click handler of the button could be used to drive population of drop-down list 1. I'll try and work on a server binding sample for you.


Odd -- I was trying my own code (pretty much the exact code as above) and I get an "Unknown Error". I tried this code, and I get the same error. Its a pretty vague error, but any ideas as to where I should begin to look?

Thanks!


I checked this code ( the good one ) and put one breakpoint at first line in page load method. Every time I changed the option in the DropDownList and the application stopped on the breakpoint.

I don't know if this control (UpdatePanel ) works in this way or is something wrong in the code but I supossed that the panel is updated with an asynchronous server call. Could anybody explain me the functionality of the control?

Thanks.


The Code is Good But Doesnt Work ...

Please help ..

No comments:

Post a Comment