dropdownlist 选中值

zhengchengbaishi 2011-04-14 09:12:08

前台部分代码 : <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();
...全文
37 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhengchengbaishi 2011-04-14
  • 打赏
  • 举报
回复
恩,对了,谢谢,太马虎了!
xu56180825 2011-04-14
  • 打赏
  • 举报
回复
dept='" +chazhao+ "'
需要单引号
zhengchengbaishi 2011-04-14
  • 打赏
  • 举报
回复
DropDownList1.SelectValue
这样我试过了,结果还是说列名‘信息工程系’无效
xu56180825 2011-04-14
  • 打赏
  • 举报
回复
DropDownList1.SelectValue
还有你这样是会被注入的

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧