时间仓促,代码写的乱,莫怪,着影区不用理会(功能之外)
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Jquery-Easy-UI/jquery.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Jquery-Easy-UI/jquery.easyui.min.js")" type="text/javascript"></script> <link href= "@Url.Content("/Jquery-Easy-UI/themes/icon.css")" rel="stylesheet" /> <link href="@Url.Content("../../Jquery-Easy-UI/themes/black/easyui.css")" rel="stylesheet" type="text/css" /> <script src="@Url.Content("~/Jquery-Easy-UI/locale/easyui-lang-zh_CN.js")" type="text/javascript"></script>
前台代码如下:
省:性别:查询
后台代码如下
public JsonResult QueryStudents() { string pro = Request["pro"]; string sex = Request["sex"]; int rows = Convert.ToInt32(Request["rows"]); int page = Convert.ToInt32(Request["page"]); Listparameters = new List (); parameters.Add(new SqlParameter("@cureentPage", page)); parameters.Add(new SqlParameter("@pageSize", rows)); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(@" WITH students AS (SELECT *, ROW_NUMBER() OVER (order by AutoKey) as RowNumber FROM Student where 1=1 "); if (pro != null && pro != "") { stringBuilder.Append(" and Province=@province"); parameters.Add(new SqlParameter("@province", pro)); } if (sex != null && sex != "") { stringBuilder.Append(" and Sex=@sex"); parameters.Add(new SqlParameter("@sex", sex)); } stringBuilder.Append(" ) "); stringBuilder.Append(@"SELECT * FROM students WHERE RowNumber between @cureentPage*@pageSize-@pageSize+1 and @cureentPage*@pageSize"); string sql = stringBuilder.ToString(); List stus = SelectMethod.SelectStudent(sql, parameters); int total; using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=BBS;uid=sa;pwd=sa")) { conn.Open(); List param=new List (); StringBuilder sb = new StringBuilder(); sb.Append("select count(*) from Student where 1=1"); if (pro != null && pro != "") { sb.Append(" and Province=@province"); param.Add(new SqlParameter("@province", pro)); } if (sex != null && sex != "") { sb.Append(" and Sex=@sex"); param.Add(new SqlParameter("@sex", sex)); } string selectedCountsql = sb.ToString(); using (SqlCommand sqlcmd = new SqlCommand(selectedCountsql, conn)) { if (param!=null) { foreach (SqlParameter sp in param) { sqlcmd.Parameters.Add(sp); } } total = Convert.ToInt32(sqlcmd.ExecuteScalar()); } } return Json(new { total = total, rows = stus }, "text/html", Encoding.UTF8, JsonRequestBehavior.AllowGet); }
对应表如下: