I have used one dropdown and three panels. Three panels are inside the updatepanel and the dropdown list is outside the updatepanel. I have initially hide the panels. I want to make one of the panels visible as per the selected item in the dropdownlist. The problem is when I change selection in the dropdownlist, the seletcedIndexChanged event fires, but the selected index remains -1 every time. I have set Autopostback = true in .aspx file.
Following is the code.

    <asp:DropDownList ID="ddlReportType" AutoPostBack="true" runat="server" OnSelectedIndexChanged="ddlReportType_SelectedIndexChanged" >
        <asp:ListItem Selected="True">-- Select which data you want to enter --</asp:ListItem>
        <asp:ListItem Value="Salse" Text="Salse">Salse Reports</asp:ListItem>
        <asp:ListItem Value="Inventory" Text="Inventory">Inventory Reports</asp:ListItem>
        <asp:ListItem Value="Finance" Text="Finance">Financial Reports</asp:ListItem>
    </asp:DropDownList>
    <br />
    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    <br />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>

             <asp:Panel ID="pnlProductSale"  runat="server">

                 <asp:Label ID="lblCaptionSales" runat="server" Text="Total Product based sale"></asp:Label>
                 <table>
                     <tr>
                         <td>
                             Select Product
                         </td>
                         <td>
                              <asp:DropDownList ID="ddlProduct" runat="server"></asp:DropDownList>
                         </td>
                     </tr>
                     </table>


             </asp:Panel>

               <asp:Panel ID="pnlInventory" runat="server">

                 <asp:Label ID="lblInventory" runat="server" Text="Inventory"></asp:Label>
                 <table>
                     <tr>
                         <td>
                             Select Product
                         </td>
                         <td>
                              <asp:DropDownList ID="ddlProductPnl2" runat="server"></asp:DropDownList>
                         </td>
                     </tr>
                 </table>
             </asp:Panel>

            <asp:Panel ID="pnlCashFlow" runat="server">
            <asp:Label ID="lblCaption" runat="server" Text="Cashflow"></asp:Label>
    <table>
        <tr>
            <td>
                Deposit at start up
            </td>
            <td>
                Cash on hand :   <asp:TextBox ID="txtStartAmt" Text="0" AutoPostBack="true" runat="server" ></asp:TextBox>
                Credit :  <asp:TextBox ID="txtStartCredit" Text="0" AutoPostBack="true" runat="server" ></asp:TextBox>
                Debit :  <asp:TextBox ID="txtstartDebit" Text="0" AutoPostBack="true" runat="server" ></asp:TextBox>
            </td>
        </tr>

    </table>

                </asp:Panel>


            </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddlReportType" />

        </Triggers>
        </asp:UpdatePanel>
Following is the code in .cs file
   protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
                pnlCashFlow.Visible = false;
                pnlProductSale.Visible = false;
                pnlInventory.Visible = false;
            }
        }

        protected void ddlReportType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlProduct.SelectedIndex == 0)
            {
                Label1.Text = ddlProduct.SelectedValue;
                pnlCashFlow.Visible = false;
                pnlProductSale.Visible = false;
                pnlInventory.Visible = true;
            }
            else if (ddlProduct.SelectedIndex ==1)
            {
                Label1.Text = ddlProduct.SelectedValue;
                pnlCashFlow.Visible = false;
                pnlProductSale.Visible = true;
                pnlInventory.Visible = false;
            }
            else if (ddlProduct.SelectedIndex==2)
            {
                Label1.Text = ddlProduct.SelectedValue;
                pnlCashFlow.Visible = true;
                pnlProductSale.Visible = false;
                pnlInventory.Visible = false;
            }
            else 
            {
                Label1.Text = ddlProduct.SelectedValue;
                pnlCashFlow.Visible = true;
                pnlProductSale.Visible = false;
                pnlInventory.Visible = false;
            }
        }

Please help me to solve this problem.

int selectedIndex = ((DropDownList)sender).SelectedIndex;

Not sure, perhaps the combo needs to be inside the UpdatePanel for your code to work. Haven't tried.

DropdownList should be inside UpdatePanel. Then the code will work.. And Trigger is also not necessary.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.