asp.net - 从下拉列表中选择一个值,并在转发器控件中显示与该选定值相关的所有信息
问题描述
我有一个下拉列表和一个转发器控件。我已经用数据库中的部门名称填充了下拉列表。我正在努力从下拉列表中选择一个部门,并让该部门的所有员工都显示在转发器控件中。任何帮助将不胜感激。
这是我的下拉列表
<asp:DropDownList ID="drplstDepartment" OnSelectedIndexChanged="drplstDepartment_SelectedIndexChanged" CssClass="form-control mb-2 mr-sm-2" runat="server" AutoPostBack="true" AppendDataBoundItems="true">
</asp:DropDownList>
这是我的中继器控件
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<%--<p>All The Data Is Shown</p>--%>
<table class="table table-default table-striped table-bordered table-condensed table-hover table-responsive">
<tr style="text-align:center;">
<th>Department</th>
<th>Cost Centre</th>
<th>Name</th>
<th>Surname</th>
<th>ID Number</th>
<th>Clock Number</th>
<th>Date Tested</th>
<th>Next Due Date</th>
<th>ECG</th>
<th>Lung Function</th>
<th>Hearing Test</th>
<th>Eye Test</th>
<th>Other Problems</th>
<th>Notes</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("LongDescription") %></td>
<td><%# Eval("Code") %></td>
<td><%# Eval("FirstName") %></td>
<td><%# Eval("LastName") %></td>
<td><%# Eval("EmployeeID") %></td>
<td><%# Eval("Code") %></td>
<td><%# Eval("[Date tested]") %></td>
<td><%# Eval("[Next Due date]") %></td>
<td><%# Eval("[ECG]") %></td>
<td><%# Eval("[Lungfunction]") %></td>
<td><%# Eval("[Hearing Test]") %></td>
<td><%# Eval("[Eye Test]") %></td>
<td><%# Eval("[Other Problems]") %></td>
<td><%# Eval("[Notes]") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
解决方案
这是我填充下拉列表的代码
Protected Sub FillWithDepartments()
Dim conn As New SqlConnection("server=XX; Integrated Security = true")
conn.Open()
Dim cmd As New SqlCommand("SELECT * FROM Departments Order By LongDescription ASC", conn)
Dim adapter As New SqlDataAdapter(cmd)
Dim tbl As New DataTable()
adapter.Fill(tbl)
drplstDepartment.DataSource = tbl
drplstDepartment.DataTextField = "LongDescription"
drplstDepartment.DataValueField = "Code"
drplstDepartment.DataBind()
conn.Close()
End Sub
这是我希望从下拉列表中选择的文本/值填充我的转发器控件的代码
Protected Sub drplstDepartment_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim connString As New SqlConnection(ConfigurationManager.ConnectionStrings("LumotechPortal.My.MySettings.GuHR_Data").ToString())
connString.Open()
Dim cmdText = "select * from [EmployeeMedicalTest] WHERE (LongDescription = @LongDescription)"
Dim Data = New DataTable()
Dim Adapter = New SqlDataAdapter(cmdText, connString)
Adapter.SelectCommand.Parameters.AddWithValue("@LongDescription", drplstDepartment.SelectedValue)
Adapter.Fill(Data)
Repeater1.DataSource = Data
Repeater1.DataBind()
connString.Close()
End Sub
推荐阅读
- angular - 角度继承组件
- python - 为什么 Google Trend 站点返回的数据缩放到一个关键字的最大量,而 pytrend 为每个关键字返回一个最大值?
- java - 如何使用 Spring Boot 在我的 postgres 数据库中创建一个表?
- html - 下载文件时边框和背景移动
- javascript - 使用 vanilla javascript 将单个子元素插入/附加到多个父元素
- pycharm - pycharm问题非项目文件
- react-native-android - react-native android:可能的未处理承诺拒绝(id:0):TypeError:网络请求失败
- html - 带有背景图像的标签
- python - 在 python 中使用 ast 从字符串表达式中排序变量名时出错
- python - 覆盖面板布局组件?