【发布时间】:2019-10-04 03:32:41
【问题描述】:
我的下拉功能有问题。下拉函数假设从数据库中获取值。我认为问题出在 sql select 命令上,但我对这种东西(asp.net 和 sql)是新手。谁能帮帮我,提前谢谢你。
这是 SQL DataSourceID
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:*****ConnectionString %>" SelectCommand="SELECT TOP 10
C.CASE_KEY, C.DEPARTMENT_CASE_NUMBER, D.DEPARTMENT_NAME, O.OFFENSE_DESCRIPTION AS CHARGE, LAB_CASE,
OFFENSE_DATE
FROM TV_LABCASE C
INNER JOIN TV_DEPTNAME D ON C.DEPARTMENT_CODE = D.DEPARTMENT_CODE
INNER JOIN TV_OFFENSE O ON C.OFFENSE_CODE = O.OFFENSE_CODE
ORDER BY CASE_DATE DESC
"></asp:SqlDataSource>
输入字段的代码
<table class="style2" >
<tr>
<td class="style3" >Department Case #</td>
<td> <asp:TextBox ID="TextBox1" runat="server" Enabled="False" ontextchanged="btnCancel_Click"></asp:TextBox></td>
</tr>
<tr>
<td class="style3">Department</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server"
Height="18px" Width="166px" Enabled="False">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style3">Charge</td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server"
Height="25px" Width="165px" Enabled="False">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style3">Lab Case #</td>
<td><asp:TextBox ID="TextBox4" runat="server" Enabled="False" ontextchanged="btnCancel_Click"></asp:TextBox></td>
</tr>
<tr>
<td class="style3">Incident Report Date</td>
<td><asp:TextBox ID="TextBox5" runat="server" Enabled="False" ontextchanged="btnCancel_Click"></asp:TextBox></td>
</tr>
</table>
ASP.NET C#(服务器端代码)
protected void Page_Load(object sender, EventArgs e)
{
string connetionString;
SqlConnection cnn;
connetionString = @"Data Source=A**SE****D***\MSSQL****;Initial Catalog=****;User
ID=****;Password=****";
cnn = new SqlConnection(connetionString);
cnn.Open();
SqlCommand cmd = new SqlCommand("select * from TV_LABCASE", cnn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
DropDownList1.DataTextField = "DEPARTMENT_NAME";
DropDownList1.DataValueField = "DEPARTMENT_CODE";
DropDownList1.DataBind();
DropDownList2.DataSource = dt;
DropDownList2.DataBind();
DropDownList2.DataTextField = "OFFENSE_DESCRIPTION";
DropDownList2.DataValueField = "OFFENSE_CODE";
DropDownList2.DataBind();
}
【问题讨论】: