简体   繁体   中英

Display selected value from table with dropdownlist

I need to display the user details depends on his primary type, if the user will choose parent from dropdownlist, I want the table to show only the users with primary type value 1, or teacher with value 2 etc.

This is my code

 <div class="row">
              <asp:DropDownList runat="server" onclickEvent="DropDownSelect">
                  <asp:ListItem></asp:ListItem>
                  <asp:ListItem Value="1">Parent</asp:ListItem>
                  <asp:ListItem Value="2">Teacher</asp:ListItem>
                  <asp:ListItem Value="3">User</asp:ListItem>
                  <asp:ListItem Value="4">Student</asp:ListItem>
              </asp:DropDownList>
          </div>
            <h2 class="panel-title">Users List</h2>
         </header>

         <div class="panel-body">
            <asp:GridView runat="server" PageSize="15" AllowPaging="True" DataSourceID="userDS" AutoGenerateColumns="False" CssClass="table table-bordered table-striped mb-none">
               <PagerStyle CssClass="dataTables_paginate paging_bs_normal" HorizontalAlign="Left" 
                  VerticalAlign="Middle" 
                  Font-Size="14pt" Wrap="True" />
               <Columns>
                  <asp:boundfield datafield="userName" headertext="Username"/>
                  <asp:boundfield datafield="eMailAddress" headertext="Email Address"/>
                  <asp:boundfield datafield="firstName" headertext="First Name"/>
                  <asp:boundfield datafield="lastName" headertext="Last Name"/>
                  <asp:boundfield datafield="organization" headertext="Organization"/>
                  <asp:boundfield datafield="roletitle" headertext="Role"/>
                  <asp:boundfield datafield="city" headertext="City"/>
                  <asp:boundfield datafield="primaryType" headertext="P. Type"/>
                  <asp:boundfield datafield="state" headertext="State"/>
                  <asp:boundfield datafield="accessCodeUsed" headertext="Access Code"/>
                  <asp:TemplateField>
                     <ItemTemplate>
                        <a class="modal-with-form btn btn-default editUserButton" href="#modalForm">Edit</a>
                     </ItemTemplate>
                  </asp:TemplateField>
                  <asp:TemplateField>
                     <ItemTemplate>
                        <a class="mb-xs mt-xs mr-xs modal-basic btn btn-danger deleteUserButton" href="#modalDeleteUser">Delete</a>
                     </ItemTemplate>
                  </asp:TemplateField>
               </Columns>
            </asp:GridView>
         </div>

Please refer to below article to see the scenario similar to yours and how its been solved.

http://www.aspsnippets.com/Articles/Filter-GridView-with-DropDownList-using-FilterExpression-in-SqlDataSource-in-ASPNet.aspx

Basically, you need to always provide "ID" value to all server-side HTML controls in Asp.NET. Also, set AutoPostBack property to true for controls such as DropDownList, if you need some actions to be performed when user changes its value. In your case, you just need to refresh the table (ie, data source of the other control) you dont need to write Event Handler and you can simply apply Filter Expression as explained the given link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM