我想要的是從下拉列表中選擇的項目中獲取值,並使用它在按鈕單擊事件中查詢(選擇表格)。如何從下拉列表框中獲取值
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>
我在哪裏可以把那一行? – user1954418 2013-03-13 06:42:21
也刪除,如果(SelectedIndex == 1)條件。 該條件沒有任何意義,因爲您希望在SQL查詢中使用SelectedValue。 – 2013-03-13 06:51:37