Link to home
Start Free TrialLog in
Avatar of rckrch
rckrchFlag for United States of America

asked on

DropDownList.SelectedValue not updating with external input


I am having trouble with a dropdownlist control not working for the dropdownlist.selectedvalue event.  

The dropdownlist populates at page load fine and all values are in the control, but the control simply will not change value when prompted in a in the code.  I am not using a client click event of the control to change the selected value - but instead trying to change it programmatically from the input from another page.


ASP.Net 

<asp:UpdatePanel ID="DataUpdate" runat="server" UpdateMode="Conditional">

            <ContentTemplate>
                
            
            <asp:Table ID="Table1" runat="server" Width="100%" CellPadding="0" CellSpacing="0" BorderStyle="None"
                Font-Names="Arial" Font-Size="12" ForeColor="#003366">
                <asp:TableRow runat="server">
                    <asp:TableCell runat="server" ColumnSpan="2" Width="100%" HorizontalAlign="Center">
                        <asp:Label ID="Label31" runat="server" Text="Select Date Range For Capability Analysis" Font-Names="Arial"
                            Font-Size="12" ForeColor="#336699"></asp:Label><br />
                        <br />
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow runat="server">
                    <asp:TableCell runat="server" ColumnSpan="2" Width="100%" HorizontalAlign="Center">

                        <asp:Label ID="Label29" runat="server" Text="Most Distant Date:  " Font-Names="Arial"
                            Font-Size="12" ForeColor="#336699"></asp:Label>
                        <asp:DropDownList ID="ScndDateCal" runat="server" DataSourceID="DateDataSource" 
                            DataValueField="Cur_Date" AutoPostBack="True" ViewStateMode="Enabled">

                        </asp:DropDownList>
                        &nbsp;&nbsp;
                        <asp:Label ID="Label28" runat="server" Text="Most Recent Date:  " Font-Names="Arial"
                            Font-Size="12" ForeColor="#336699"></asp:Label>
                        <asp:DropDownList ID="FrstDateCal" runat="server" DataSourceID="DateDataSource" 
                            DataValueField="Cur_Date" AutoPostBack="True" ViewStateMode="Enabled">

                        </asp:DropDownList>
                        <asp:SqlDataSource ID="DateDataSource" runat="server"
                            ConnectionString="<%$ ... %>"
                            ProviderName="<%$ ... %>"
                            SelectCommand="SELECT [Cur_Date] FROM [DataTable] WHERE ([DieNumber] = ?) AND ([PartNumber] = ? or [PartNumber] = 'All') AND ([MetricName] = ?) ORDER BY Cur_Date DESC"><%--[PartNumber],  <%--AND ([PartNumber] = ?)--%> <%--ORDER BY RecordID DESC--%>
                            <SelectParameters>
                                <asp:Parameter DefaultValue="Die Number" Name="DieNumber" Type="String" />
                                <asp:Parameter DefaultValue="Part Number" Name="PartNumber" Type="String" />
                                <asp:Parameter DefaultValue="Metric Name" Name="MetricName" Type="String" />
                            </SelectParameters>
                        </asp:SqlDataSource><br /><br />
                    </asp:TableCell>
                </asp:TableRow>
            </asp:Table>
            
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="FrstDateCal" EventName="SelectedIndexChanged" />
                    <asp:AsyncPostBackTrigger ControlID="ScndDateCal" EventName="SelectedIndexChanged" />
                </Triggers>
            </asp:UpdatePanel>

Open in new window

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            PartNoVal.Text = Session("prtnoval")
            DieNoVal.Text = Session("dienoval")
            MetricVal.Text = Session("metricval")
            ViewState("xmaxscale") = Session("xmaxscale")
            ViewState("xminscale") = Session("xminscale")
            
            DateDataSource.SelectParameters("DieNumber").DefaultValue = DieNoVal.Text
            DateDataSource.SelectParameters("PartNumber").DefaultValue = PartNoVal.Text
            DateDataSource.SelectParameters("MetricName").DefaultValue = MetricVal.Text
            DateDataSource.DataBind()

            FrstDateCal.DataBind()
            ScndDateCal.DataBind()

            BindChart()
        Else
            BindChart()
 End If
    End Sub
Protected Sub FrstDateCal_SelectedIndexChanged() Handles FrstDateCal.SelectedIndexChanged
        FrstDateCal.SelectedValue = ViewState("xmaxscale")
        DataUpdate.Update()
    End Sub
    Protected Sub ScndDateCal_SelectedIndexChanged() Handles ScndDateCal.SelectedIndexChanged
        ScndDateCal.SelectedValue = ViewState("xminscale")
        DataUpdate.Update()
    End Sub

Open in new window

 

Avatar of louisfr
louisfr

It's the values in Session("xmaxscale") and Session("xminscale") you want to set the dropdownlists to?
Did you try setting them in the Page_Load event?
Avatar of rckrch

ASKER

Yes, those session values are the values to use.  Yes, I tried doing it in Page_Load as well.
Try the Page_PreRender event instead. Regardless, the values need to already be available in the control before they can be selected. The Page Lifecycle comes into play here.
Avatar of rckrch

ASKER

Yes, the values are available in the control.  All values are loaded fine in the control, but the programmatic select command will simply not select the target value (that is present) in the control.
Understood, but I'm talking about:
1. Debugging the code so that you can verify that at the point of time when it tries to set the value that it's availalble.
2. Nothing is overwriting the setting after that point.
Avatar of rckrch

ASKER

Yes, that is when it is verified to be populated - during debugging.  I verified that the full list of available data points from the database are loaded.  The verification of the loaded data is done during debugging at the point when the SelectedValue command is invoked.    
ASKER CERTIFIED SOLUTION
Avatar of Kelvin McDaniel
Kelvin McDaniel
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rckrch

ASKER

Thanks Kelvin,

I'll try this and let you know.
According to the documentation, the SelectedValue property is a getter, not a setter.
I don't think the documentation says that.
On the contrary : "The SelectedValue property can also be used to select an item in the list control by setting it with the value of the item."