ASP.NET查(高手)
要做表的查:
表一:SFCYML
字段:ML001()、ML002()、ML005(工)、ML006(工)、ML015(品)、ML011(投入批)、ML012(出批)、ML016()、ML017(各段)、ML052(幅)、ML007()、ML001();
表二:MOCTA
字段:TA001、TA002、UDF01(客)
表系:ML005和TA001;ML006和TA002
要用通入品号(品)或出批(ML012)或工(ML006)
查.
要示的信息:、、工、工、品、投入批、出批、、各段、幅、、、客.
全部示我已,怎查???
search.aspx:
Language= "C# " AutoEventWireup= "true " CodeFile= "Default.aspx.cs " EnableEventValidation = "false " Inherits= "UI_Default " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head id= "Head1 " runat= "server ">
<title> 无标题页 </title>
<link href= "../StyleSheet.css " rel=Stylesheet type= "text/css " />
</head>
<body>
<center>
<form id= "form1 " runat= "server ">
<div>
<asp:Panel ID= "Panel1 " runat= "server " Height= "23px " Width= "850px ">
<asp:Label ID= "Label1 " runat= "server " Text= "查件: " ForeColor= "#666666 "> </asp:Label>
<asp:DropDownList ID= "DropDownList1 " runat= "server " Font-Names= "宋体 " Font-Size= "9pt ">
<asp:ListItem Value= "ML015 "> 品 </asp:ListItem>
<asp:ListItem Value= "ML011 "> 投入批 </asp:ListItem>
<asp:ListItem Value= "ML012 "> 出批 </asp:ListItem>
<asp:ListItem Value= "Ml006 "> 工 </asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID= "DropDownList2 " runat= "server " Font-Names= "宋体 " Font-Size= "9pt ">
</asp:DropDownList>
<asp:TextBox ID= "TextBox1 " runat= "server " Height= "13px " Font-Names= "宋体 " Font-Size= "9pt "> </asp:TextBox>
<asp:Button ID= "Button5 " runat= "server " Text= "查找 " BackColor= "#EEEEEE " Font-Names= "宋体 " Font-Size= "9pt " ForeColor= "#666666 " /> </asp:Panel>
<br />
<asp:GridView ID= "GridView1 " runat= "server " AutoGenerateColumns= "False " Height= "111px " Width= "850px " OnRowCreated= "GridView1_RowCreated " style= "color: gray ">
<PagerSettings Mode= "NextPreviousFirstLast " Visible= "False "/>
<HeaderStyle BackColor= "DodgerBlue " Font-Bold=True ForeColor=White />
<Columns>
<asp:BoundField DataField= "ML001 " HeaderText= " " SortExpression= "ML001 " />
<asp:BoundField DataField= "ML002 " HeaderText= " " SortExpression= "ML002 " />
<asp:BoundField DataField= "ML005 " HeaderText= "工 " SortExpression= "ML005 " />
<asp:BoundField DataField= "ML006 " HeaderText= "工 " SortExpression= "ML006 " />
<asp:BoundField DataField= "ML015 " HeaderText= "品 " SortExpression= "ML015 " />
<asp:BoundField DataField= "ML011 " HeaderText= "投入批 " SortExpression= "ML011 " />
<asp:BoundField DataField= "ML012 " HeaderText= "出批 " SortExpression= "ML012 " />
<asp:BoundField DataField= "ML016 " HeaderText= " " SortExpression= "ML016 " />
<asp:BoundField DataField= "ML017 " HeaderText= "各段 " SortExpression= "ML017 " />
<asp:BoundField DataField= "ML052 " HeaderText= "幅 " SortExpression= "ML052 " />
<asp:BoundField DataField= "ML007 " HeaderText= " " SortExpression= "ML007 " />
<asp:BoundField HeaderText= "客 " DataField= "UDF01 " SortExpression= "UDF01 " />
</Columns>
</asp:GridView>
<br />
<asp:Panel ID= "Panel2 " runat= "server " Height= "21px " Width= "850px ">
<asp:Button ID= "Button1 " runat= "server " OnClick= "Button1_Click " Text= "首 " CommandArgument= "first " CommandName= "page " Font-Names= "宋体 " Font-Size= "9pt " BackColor= "#EEEEEE " ForeColor= "#666666 " />
<asp:Button ID= "Button2 " runat= "server " OnClick= "Button1_Click " Text= "上一 " CommandArgument= "prev " CommandName= "page " BackColor= "#EEEEEE " Font-Names= "宋体 " Font-Size= "9pt " ForeColor= "#666666 " />
<asp:Button ID= "Button3 " runat= "server " OnClick= "Button1_Click " Text= "下一 " CommandArgument= "next " CommandName= "page " BackColor= "#EEEEEE " Font-Names= "宋体 " Font-Size= "9pt " ForeColor= "#666666 " />
<asp:Button ID= "Button4 " runat= "server " OnClick= "Button1_Click " Text= "末 " CommandArgument= "last " CommandName= "page " BackColor= "#EEEEEE " Font-Names= "宋体 " Font-Size= "9pt " ForeColor= "#666666 " /> </asp:Panel>
</div>
</form> </center>
</body>
</html>
search.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class UI_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
private void bind()
{ //建立一个方法,用与在页面中为控件绑定数据
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[ "YS999ConnectionString "].ConnectionString);
//初始化连接
SqlDataAdapter sda = new SqlDataAdapter( "select SFCYML.ML001,SFCYML.ML002,SFCYML.ML005,SFCYML.ML006,SFCYML.ML015,SFCYML.ML011,SFCYML.ML012,SFCYML.ML016,SFCYML.ML017,SFCYML.ML052,SFCYML.ML007,MOCTA.TA001,MOCTA.TA002,MOCTA.UDF01 from SFCYML Inner Join MOCTA on SFCYML.ML005=MOCTA.TA001 and SFCYML.ML006=MOCTA.TA002 ", con);
DataSet ds = new DataSet();
sda.Fill(ds, "SFCYML ");
GridView1.DataSource = ds.Tables[ "SFCYML "];
GridView1.AllowPaging = true;//设置他可以分页,前台必须设置分页模板不可见,否则他要使坏
GridView1.PageSize = 40;//分页大小为10
GridView1.DataBind();
if (GridView1.PageIndex == 0)
{//如果当前为首页,那么上页和首页按纽不可用
Button1.Enabled = false;
Button2.Enabled = false;
}
else
{
Button1.Enabled = true;
Button2.Enabled = true;
}
if (GridView1.PageIndex == GridView1.PageCount - 1)
{//如果当前为末页,那么下页和末页按纽不可用
Button3.Enabled = false;
Button4.Enabled = false;
}
else
{
Button3.Enabled = true;
Button4.Enabled = true;
}
}
protected void Button1_Click(object sender, EventArgs e)
{//实现分页
switch (((Button)sender).CommandArgument.ToString())
{
case "first ":
GridView1.PageIndex = 0;
break;
case "last ":
GridView1.PageIndex = GridView1.PageCount - 1;
break;
case "prev ":
GridView1.PageIndex = GridView1.PageIndex - 1;
break;
case "next ":
GridView1.PageIndex = GridView1.PageIndex + 1;
break;
}
bind();
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{//鼠标行为
if (e.Row.RowType == DataControlRowType.DataRow)//判行是否行,行鼠作
{
e.Row.Attributes.Add( "onmouseover ", "c=this.style.backgroundColor;this.style.backgroundColor= '#eeeeee ' ");
e.Row.Attributes.Add( "onmouseout ", "this.style.backgroundColor=c; ");
}
}
}
[解决办法]
太长了,很少人会看的
------解决方案--------------------
说简单点,说重点。
[解决办法]
扔到SQL区
[解决办法]
查询?太广了的,首先你得明确需要根据哪几个字段查询,然后在你已有的sql语句上面添加where条件就可以了
select SFCYML.ML001,SFCYML.ML002,SFCYML.ML005,SFCYML.ML006,SFCYML.ML015,SFCYML.ML011,SFCYML.ML012,SFCYML.ML016,SFCYML.ML017,SFCYML.ML052,SFCYML.ML007,MOCTA.TA001,MOCTA.TA002,MOCTA.UDF01 from SFCYML Inner Join MOCTA on SFCYML.ML005=MOCTA.TA001 and SFCYML.ML006=MOCTA.TA002 where 。。。。
[解决办法]
太长了