Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5953099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:46:34+00:00 2026-05-22T17:46:34+00:00

I have two dropdownlist, a detailsview and a formview control in my page. The

  • 0

I have two dropdownlist, a detailsview and a formview control in my page. The first dropdownlist has a list of categories of books, while the second dropdownlist has a list of books based on the selected value of the first dropdownlist and lastly the detailsview which shows the details second dropdownlist. The formview on the other hand doesnt have any control and I just use it to get the value from the detailsview for inserting record based on the second selected dropdownlist. So what I want to do is hide the formview if the second dropdownlist is empty.

Its a bit unclear but to make things short I just want to hide the formview if theres no value selected in the second dropdownlist (and show if there is).

I have attached my sample code. I hope you could understand.

Thanks in advance

<p>
        Book Reservation</p>
    <p>
        <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" 
            AutoPostBack="True" DataSourceID="categoryDataSource" DataTextField="name" 
            DataValueField="categoryid" >
            <asp:ListItem Selected="True" Value="">-- Choose a category --</asp:ListItem>
        </asp:DropDownList>
        <asp:SqlDataSource ID="categoryDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>" 
            SelectCommand="SELECT [categoryid], [name] FROM [TblCategory]" >
        </asp:SqlDataSource>
    </p>
    <p>
        <asp:DropDownList ID="DropDownList2" runat="server"
            AutoPostBack="True" DataSourceID="booktitleDataSource"
            DataTextField="booktitle" DataValueField="bookid" OnDataBound="DetailsView1_DataBound" >
        <asp:ListItem Selected="True" Value="-1">-- Choose a book --</asp:ListItem>
        </asp:DropDownList>

        <asp:SqlDataSource ID="booktitleDataSource" runat="server"
            ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>" 
            SelectCommand="SELECT [bookid], [booktitle], [categoryid] FROM [TblBooks] WHERE ([categoryid] = @categoryid)">
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="categoryid" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource> 
    </p>
    <p>
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
            DataKeyNames="bookid" DataSourceID="bookdetailsDataSource" >
            <HeaderTemplate>
            <b>BOOK DETAILS</b>
            </HeaderTemplate>

            <FooterTemplate>
            <b>RESERVED BY</b>
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" 
            AutoGenerateColumns="False" DataKeyNames="reservationid"
            DataSourceID="reserveDataSource">
            <Columns>
            <asp:BoundField DataField="EmployeeID" HeaderText="Employee PIN" 
                    SortExpression="EmployeeID" />

            <asp:BoundField DataField="reservedate" HeaderText="Reserve date" 
                    SortExpression="reservedate" />
            </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="resereDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
            SelectCommand="SELECT dbo.BookReservation.reservationid,dbo.BookReservation.bookid, dbo.BookReservation.EmployeeID, 
            dbo.BookReservation.reservedate, dbo.BookReservation.isapproved, dbo.BookReservation.reschedule, dbo.BookReservation.isdeleted, 
            dbo.TblBooks.booktitle FROM dbo.BookReservation INNER JOIN dbo.TblBooks ON dbo.BookReservation.bookid = dbo.TblBooks.bookid WHERE (dbo.BookReservation.isdeleted IS NULL) OR (dbo.BookReservation.deleted = 0)">

            </asp:SqlDataSource>
            </FooterTemplate>
            <Fields>
                <asp:BoundField DataField="bookid" HeaderText="ISBN" ReadOnly="True" 
                    SortExpression="bookid" />
                <asp:BoundField DataField="booktitle" HeaderText="Title" 
                    SortExpression="booktitle" />
                <asp:BoundField DataField="lastname" HeaderText="Author" 
                    SortExpression="lastname" />
                <asp:BoundField DataField="firstname" HeaderText="" 
                    SortExpression="firstname" />
                <asp:BoundField DataField="description" HeaderText="Description" 
                    SortExpression="description" />
                <asp:BoundField DataField="name" HeaderText="Category" 
                    SortExpression="name" />
                <asp:BoundField DataField="quantity" HeaderText="Quantity" 
                    SortExpression="quantity" />
                <asp:BoundField DataField="dateadded" HeaderText="Date added" 
                    SortExpression="dateadded" />
                <asp:CheckBoxField DataField="isdeleted" HeaderText="Deleted" 
                    SortExpression="isdeleted" />
            </Fields>
        </asp:DetailsView>
        <asp:SqlDataSource ID="bookdetailsDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>" 
            SelectCommand="SELECT dbo.TblBooks.bookid, dbo.TblBooks.booktitle, dbo.TblBooks.lastname, dbo.TblBooks.firstname, dbo.TblBooks.description, dbo.TblBooks.categoryid, dbo.TblBooks.dateadded, dbo.TblBooks.statusid, dbo.TblBooks.quantity, dbo.TblBooks.isdeleted, dbo.BookStatus.statusname, dbo.TblCategory.name, dbo.LendTable.EmployeeID, dbo.LendTable.dateborrowed, dbo.LendTable.expdateofreturn, dbo.LendTable.datereturned FROM dbo.TblBooks INNER JOIN dbo.TblCategory ON dbo.TblBooks.categoryid = dbo.TblCategory.categoryid INNER JOIN dbo.BookStatus ON dbo.TblBooks.statusid = dbo.BookStatus.statusid INNER JOIN dbo.LendTable ON dbo.TblBooks.bookid = dbo.LendTable.bookid WHERE (dbo.TblBooks.bookid = @bookid) ">
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList2" Name="bookid" 
                    PropertyName="SelectedValue" Type="Int64" />
            </SelectParameters>
        </asp:SqlDataSource>
    </p>
    <p>
        <asp:FormView ID="FormView1" runat="server" DataKeyNames="reservationid" 
            DataSourceID="reserveDataSource" DefaultMode="Insert" 
            OnDataBound="FormView1_DataBound" >

            <EditItemTemplate>
                reservationid:
                <asp:Label ID="reservationidLabel1" runat="server" 
                    Text='<%# Eval("reservationid") %>' />
                <br />
                bookid:
                <asp:TextBox ID="bookidTextBox" runat="server" Text='<%# Bind("bookid") %>' />
                <br />
                EmployeeID:
                <asp:TextBox ID="EmployeeIDTextBox" runat="server" 
                    Text='<%# Bind("EmployeeID") %>' />
                <br />
                reservedate:
                <asp:TextBox ID="reservedateTextBox" runat="server" 
                    Text='<%# Bind("reservedate") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                    &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>

            <InsertItemTemplate>

                Reserve date:
                <asp:TextBox ID="reservedateTextBox" runat="server" 
                    Text='<%# Bind("reservedate") %>' />
                <a href="#" onclick="cdp1.showCalendar(this, 'ctl00$ContentPlaceHolder1$FormView1$reservedateTextBox'); return false;">Date Picker</a>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="reservedateTextBox" ErrorMessage="* " ValidationGroup="reservebook">
                </asp:RequiredFieldValidator>
                <br />

                <asp:Button ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                    &nbsp;<asp:Button ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />

                <%--ISBN:--%>
                <asp:TextBox ID="bookidTextBox" runat="server" Visible="false" 
                    Text='<%# Bind("bookid") %>' />
                <br />
                <%--Employee PIN:--%>
                <asp:TextBox ID="EmployeeIDTextBox" runat="server" Visible="false" 
                    Text='<%# Bind("EmployeeID") %>' />
                <br />

            </InsertItemTemplate>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:46:35+00:00Added an answer on May 22, 2026 at 5:46 pm

    1) Set FromView Visible="False" initially, from the markup.
    2) assign OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" to DropDownList2 and set its AutoPostBack="True"

    3) in the code behind add this:

    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        if(!DropDownList2.SelectedValue.Equals("-1"))
            FromView1.Visible=true;
        else
            FromView1.Visible=false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WebForms page that has two DropDownList controls on it that both
I am using MVC3, EF Model first. I have a form with two DropDownList
i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
I have two update panels at my ajax page. This is first time I'm
I have two dropdownlist which shows places in my asp.net MVC(C#) application. The First
I have two very similar .aspx pages. Both of them contain a DropDownList control.
I have two dropdowns categories and subcategories on my page. Also I have an
I have two search buttons on a page, one linked to a dropdown list
I have two dropdownlist. The selected value from the first one loads the other.
I have two controls on a page, label and dropdownlist. I have a requiredfieldvalidator

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.