小妹初学asp.net,所用工具为web developer 2005。做一订单查询界面,用dropdownlist选择“按订单号查询“或“按客户名查询“,在textbox中输入相关信息,在按button实现查询。无信息时,显示“无相关信息“。该如何传递dropdownlist和textbox中的信息,如何实现查询?请大哥们帮小妹填写下代码,毕设急用!承诺100分!<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e)
{ } protected void Button1_Click(object sender, EventArgs e)
{ } protected void Button1_Click1(object sender, EventArgs e)
{
}
</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="ord_id">按订单号</asp:ListItem>
<asp:ListItem Value="ord_customer">按客户名</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="查询" /><br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GoodsConnectionString %>"
SelectCommand="SELECT * FROM [orders]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" Width="406px">
</asp:GridView>
</form>
</body>
</html>
{ } protected void Button1_Click(object sender, EventArgs e)
{ } protected void Button1_Click1(object sender, EventArgs e)
{
}
</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="ord_id">按订单号</asp:ListItem>
<asp:ListItem Value="ord_customer">按客户名</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="查询" /><br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GoodsConnectionString %>"
SelectCommand="SELECT * FROM [orders]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" Width="406px">
</asp:GridView>
</form>
</body>
</html>
http://feiren1421.cnblogs.com/archive/2006/04/05/367537.html
protected void Button1_Click1(object sender, EventArgs e)
{
//连接数据库就没写了
string sql = "select * from [表名] where" + dropdownlist.value + "='"+textbox.text+"'";
DataSet ds = new DataSet() ;
SqlDataAdapter da = new SqlDataAdapter(sql);
da.fill(ds);
然后在ds中取值
如果有值就把数据源设给DataGrid,没有就为空
}
我忘记是哪个了~_~!!
{
sql="select * from yourtable where 订单号字段='"+TextBox1.Text+"'";//TextBox1是你输入的订单的值.
}
else
{
sql="select * from yourtable where 客户名字段='"+TextBox1.Text+"'";//TextBox1是你输入的客户名的值.
}
conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
SqlDataReader dr = cmd.ExecuteReader();
conn.Close();
{
sql="select * from yourtable where 订单号字段='"+TextBox1.Text+"'";//TextBox1是你输入的订单的值.
}
else
{
sql="select * from yourtable where 客户名字段='"+TextBox1.Text+"'";//TextBox1是你输入的客户名的值.
}
SqlDataSource.SelectCommand=sql;
private string SQLBulite()
{
string strSQL=""; if(drpliste.selectedindex==1)
{
//****按产品名称查找
strSQL+="AND PRODUCTNAME LIKE '%" + TXTPRODUCTNAME.Value + "%'";
}
else if(drpliste.SelectedIndex==2)
{
//****按产品编号查找
strSQL+=" AND PRODUCTID='" + TXTPRODUCTNAME.Value + "'";
} return strSQL;
}//*****邦定数据
private void PageLoadData()
{
int PageCurrentindex,PageCount;
string strSQL="";
//****获取查找条件
strSQL=SQLBulite();
strSQL+=" AND PRODUCTSTATE=2"; DataSet DSet=(new webservices.FrindService()).ProductInfo_Get_PageProc(out PageCurrentindex,out Page,strSQL,Asp.currentindex,Asp.PageSize);//****邦定数据.}
DropDownList不是有个ValueMember和TextMember(应该是吧,那个智能感知最大的坏处就是让人记不住那些属性名),把TextMember设置成"按订单号查询"和"按姓名查询",ValueMember设置成"订单号字段"和"姓名字段",一句话就可以解决了!
select * from Table where this.ddl1.selectValue.ToString()="'"+this.TextBox1.Text.Trim()+"'"
不需要要判断语句了!
sda.SelectCommand=new OleDbCommand("select * from table where "+this.ddl1.SelectValue.ToString()+"='"+this.TextBox1.Text.Trim()+"'",con);
DataSet ds=new DataSet();
sda.Fill(ds,"tab");
if(ds.Tables["tab"].Rows.Count==0)
{}
else
{}顺便说一句,我上面那个SQL语句有点问题,应该是这个!