我想要的是从下拉列表中的选定项目中获取值,并在按钮单击事件中使用它来查询(选择表)。
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex == 1)
{
using (SqlConnection con = new SqlConnection(DBcon))
{
SqlCommand sqlCommand = new SqlCommand("Select * from tbl_WinApps_FileHeader");
sqlCommand.Connection = con;
SqlDataReader read = sqlCommand.ExecuteReader();
GridView1.DataSource = read;
GridView1.DataBind();
}
}
}
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>ER00 - File Header</asp:ListItem>
<asp:ListItem>ER01 - Expense Report Trans</asp:ListItem>
<asp:ListItem>ER02 - Expense Report Item Trans</asp:ListItem>
<asp:ListItem>ER03 - Expense Report Item Tax Trans</asp:ListItem>
<asp:ListItem>ER04 - Expense Report Item</asp:ListItem>
</asp:DropDownList>