Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Saturday, March 24, 2012

Triggers

Can you provide a short example, or point me in the direction, of how to use the "ControlEventTrigger" - I think I have the "Control ValueTrigger" figured out - responds to a value of a control changing (right?), but I'm not sure how the EventTrigger is used - I assume it responds to an event...

Thanks,


Ed

Here is an example. The supervisor dropdown gets updated once a manager is chosen.

<asp:DropDownListID="ddlManager"runat="server"DataSourceID="odsManager"DataTextField="Manager"DataValueField="ManagerID"AutoPostBack="True"></asp:DropDownList>

<atlas:UpdatePanelID="p2"runat="server"Mode="Conditional">

<ContentTemplate>

<asp:DropDownListID="ddlSupervisor"runat="server"DataSourceID="odsSupervisor"

DataTextField="Supervisor"DataValueField="Supervisor">
</asp:DropDownList>

</ContentTemplate>

<Triggers>

<atlas:ControlEventTriggerControlID="ddlManager"EventName="SelectedIndexChanged"/> </Triggers>

</atlas:UpdatePanel>


A sample of using ControlEventTrigger is included in the ASP.Net Atlas First Look webcast (Nikhil Kothari)

Download ASP.NET "Atlas" First Look demo video

Hope this helps...


Thank you Nta and dip!
Hi,

what is the magic behind a ControlEventTrigger? well, suppose that you are using the SelectedIndexChanged event of a DropDownList as a trigger, like in the example posted by Nta.

What the trigger does is attaching an event handler to the SelectedIndexChanged event. When you make a selection in the ddl, the ddl does a postback, the SelectedIndexChanged event fires and the handler attached by the trigger is executed.

When the trigger's handler is executed, the corresponding UpdatePanel is forced to perform an update.

Wednesday, March 21, 2012

trouble with a simple scenario with Atlas(dependent dropdownlists)

Hi,

I have two dropdowns, for example states and counties.

When I change a state the right counties list should load in the counties dropdown.

It works fine with an updatepanel and a trigger to the States dropdown, until I add a "select from list" item and set AppendDataBoundItems=true. What happens is whenever I change the index of the first dropdown, the corresponding items are added to the second dropdown while it already has values from all the previous selections.

Is it possible to redraw the whole dropdown without add items from subsequent databinds?

Any suggestions would be welcome.

Thanks

hello.

can you show us a small page that reproduces the problem you're having? thanks.


Here is the code:

<

atlas:ScriptManagerID="s1"EnablePartialRendering="True"runat="server"EnableViewState="False"></atlas:ScriptManager><tablecellpadding="4"><tr><tdstyle="height: 73px"><asp:DropDownListID="ddlPosition"runat="server"AppendDataBoundItems="True"AutoPostBack="True"DataSourceID="dsPositions"DataTextField="PositionName"DataValueField="PositionID"><asp:ListItemValue="0">select from list</asp:ListItem></asp:DropDownList><asp:SqlDataSourceID="dsPositions"runat="server"ConnectionString="<%$ ConnectionStrings:conninfo %>"SelectCommand="Get_Positions"SelectCommandType="StoredProcedure"></asp:SqlDataSource></td><tdstyle="height: 73px"><atlas:UpdatePanelID="upStates"runat="server"EnableViewState="true"Mode="Conditional"><ContentTemplate><asp:DropDownListID="ddlStates"runat="server"AutoPostBack="True"DataSourceID="dsStates"DataTextField="StateName"DataValueField="StateID"AppendDataBoundItems="True"><asp:ListItemValue="0">select from list</asp:ListItem></asp:DropDownList><asp:SqlDataSourceID="dsStates"runat="server"ConnectionString="<%$ ConnectionStrings:conninfo %>"SelectCommand="Get_States_with_Jobs_by_Position"SelectCommandType="StoredProcedure"><SelectParameters><asp:ControlParameterControlID="ddlPosition"Name="PositionID"PropertyName="SelectedValue"Type="Int32"/></SelectParameters></asp:SqlDataSource></ContentTemplate><Triggers><atlas:ControlEventTriggerControlID="ddlPosition"EventName="SelectedIndexChanged"/></Triggers></atlas:UpdatePanel></td><tdstyle="height: 73px"><atlas:UpdatePanelID="upRegions"runat="server"Mode="Conditional"><ContentTemplate><asp:DropDownListID="ddlRegions"runat="server"AutoPostBack="True"DataSourceID="dsRegions"DataTextField="RegionName"DataValueField="RegionID"AppendDataBoundItems="True"><asp:ListItemValue="0">select from list</asp:ListItem></asp:DropDownList><asp:SqlDataSourceID="dsRegions"runat="server"ConnectionString="<%$ ConnectionStrings:conninfo %>"SelectCommand="Get_Regions_by_State_Position"SelectCommandType="StoredProcedure"><SelectParameters><asp:ControlParameterControlID="ddlPosition"Name="PositionID"PropertyName="SelectedValue"Type="Int32"/><asp:ControlParameterControlID="ddlStates"Name="StateID"PropertyName="SelectedValue"Type="Int32"/></SelectParameters></asp:SqlDataSource></ContentTemplate><Triggers><atlas:ControlEventTriggerControlID="ddlStates"EventName="SelectedIndexChanged"/></Triggers></atlas:UpdatePanel></td></tr><tr><tdcolspan="3"><atlas:UpdatePanelid="upGrid"runat="Server"Mode="Conditional"><ContentTemplate><asp:GridViewID="GridView1"runat="server"AllowSorting="True"AutoGenerateColumns="False"CellPadding="4"DataSourceID="dsJobs"ForeColor="#333333"GridLines="None"><FooterStyleBackColor="#5D7B9D"Font-Bold="True"ForeColor="White"/><Columns><asp:BoundFieldDataField="LocationName"HeaderText="LocationName"ReadOnly="True"SortExpression="LocationName"/></Columns><RowStyleBackColor="#F7F6F3"ForeColor="#333333"/><EditRowStyleBackColor="#999999"/><SelectedRowStyleBackColor="#E2DED6"Font-Bold="True"ForeColor="#333333"/><PagerStyleBackColor="#284775"ForeColor="White"HorizontalAlign="Center"/><HeaderStyleBackColor="#5D7B9D"Font-Bold="True"ForeColor="White"/><AlternatingRowStyleBackColor="White"ForeColor="#284775"/></asp:GridView><asp:SqlDataSourceID="dsJobs"runat="server"ConnectionString="<%$ ConnectionStrings:conninfo %>"SelectCommand="Get_Jobs_by_Regions"SelectCommandType="StoredProcedure"><SelectParameters><asp:ControlParameterControlID="ddlPosition"Name="PositionID"PropertyName="SelectedValue"Type="Int32"/><asp:ControlParameterControlID="ddlRegions"Name="RegionID"PropertyName="SelectedValue"Type="Int32"/></SelectParameters></asp:SqlDataSource></ContentTemplate><Triggers><atlas:ControlEventTriggerControlID="ddlRegions"EventName="SelectedIndexChanged"/></Triggers></atlas:UpdatePanel></td></tr></table>

any ideas?

thanks


hello.

well, presenting this kind of page will give few chances of getting an answer :(

can you build a demo page that doesn't use sqldatasource to get its data? for instance, use dummy arrays and bind them to the dropdowns a la ASP.NET 1.X...by doing this, you'll build a page that i and others (brighter than me) can simply copy and paste and run...then you'll probably get an answer.

thanks.


Does it work without the update panel?

You have this set "AppendDataBoundItems="True"which will cause this to happen - turn this off and it won't append it any longer.


You have to clear out all the items before you bind different data to them.

Use dropdownlist.items.clear()

You will have to readd any static items that you may want before databinding.