求助一个棘手的问题
院系:(文本框) 确认
我想在上面的文本框中输入院系的名称如计算机 然后按确认键就会在下面显示属于计算机系学生的信息。下面是我的代码。我遇到的问题是我每次按确认键都没有信息显示啊。求各位指导。。。。。。先谢谢了。
程序代码:
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; namespace stuinfo { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string getdept; Session.Timeout = 30; getdept = dept.Text; DataGrid.PagerStyle.Visible = true; } public void find_Click(object sender, System.EventArgs e) { SqlConnection Con =new SqlConnection("DataSource=localhost;Initial Catalog=stuinfo ;User ID=sa;Pwd='sa';"); string sel; SqlDataAdapter Cmd; sel = "select * from stu where dept.Text=dept"; if (sel.EndsWith ("and")==true) sel=sel.Remove (sel.Length-3,3); Cmd =new SqlDataAdapter(sel,Con); DataSet ds=new DataSet (); Cmd.Fill(ds,"stu"); DataGrid .DataSource =ds .Tables ["stu"].DefaultView ; DataGrid .DataBind (); } } }上面是后台代码。
程序代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="stuinfo._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www."> <html xmlns="http://www." > <head runat="server"> <title>学生信息管理</title> <style type="text/css"> .div1 { margin-top:80px; } </style> </head> <body> <form id="stuinfo" runat="server" method="post"> <p align="center" class="div1">院系:<asp:TextBox ID="dept" runat="server" Width ="100px"></asp:TextBox> <asp:Button ID="find" runat="server" Text="确认" /> </p> <table align="center" width="40%" border="0" cellpadding="0" cellspacing="0"> <tr><td><asp:datagrid ID="DataGrid" runat="server" Width="100%" PageSize="50" AllowPaging ="true" HorizontalAlign ="Center" AutoGenerateColumns ="false" > <HeaderStyle HorizontalAlign ="Center"/> <PagerStyle Position ="TopAndBottom" Mode ="NumericPages " /> <AlternatingItemStyle BackColor ="Silver" /> <ItemStyle HorizontalAlign ="Center" /> <Columns > <asp:BoundColumn DataField ="xh" HeaderText ="学号"></asp:BoundColumn> <asp:BoundColumn DataField ="xm" HeaderText ="姓名"></asp:BoundColumn> <asp:BoundColumn DataField ="xb" HeaderText ="性别"></asp:BoundColumn> <asp:BoundColumn DataField ="zy" HeaderText ="专业"></asp:BoundColumn> <asp:BoundColumn DataField ="bj" HeaderText ="班级"></asp:BoundColumn> </Columns> </asp:DataGrid> </td> </tr> </table> </form> </body> </html>上面是前台代码。
求各位的指导。。。。。。。。。。。。。。。。。。。。