dropdownlist 选中值
前台部分代码 : <asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server" Width="100px">
<asp:ListItem Selected="True" Value="信息工程系"> 信息工程系</asp:ListItem>
我想获取前台 DropDownList选中的值,比如 “信息工程系”
可是为什么我的代码没有错,运行的时候却说 列名‘信息工程系’无效呢?
<asp:ListItem Selected="True" Value="信息工程系"> 信息工程系</asp:ListItem>
string chazhao = DropDownList1.Text;
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["SqlConString"]);
con.Open();
string str = "select * from jieguo where dept=" +chazhao+ " order by total desc";
SqlDataAdapter myda = new SqlDataAdapter(str,con);
SqlCommand cmd = new SqlCommand(str);
DataSet myds = new DataSet();
myda.Fill(myds,"dd");
//DropDownList1.DataTextField = "";
//DropDownList1.DataValueField = "";
GridView1.DataSource = myds;
GridView1.DataBind();
con.Close();