如何实现ASP.NET 两个下拉框组合实现查询

guojingmail2009 2011-03-02 03:45:48
两个下拉框对应该两个文本框,如何实现组合查询,请大家帮帮忙!谢谢!
源码:

<asp:TextBox ID="txtTop" runat="server"></asp:TextBox>
<asp:DropDownList ID="ddTop" runat="server">
<asp:ListItem Value="" Text="请选择查询条件"></asp:ListItem>
<asp:ListItem Value="startDate" Text="开始日期查询"></asp:ListItem>
<asp:ListItem Value="customer" Text="客户名称查询"></asp:ListItem>
<asp:ListItem Value="billType" Text="单据类别查询"></asp:ListItem>
<asp:ListItem Value="sales" Text="业务人员查询"></asp:ListItem>
<asp:ListItem Value="billNumber" Text="单号查询"></asp:ListItem>
<asp:ListItem Value="billState" Text="单据结/未结束状态查询"></asp:ListItem>
<asp:ListItem Value="endDate" Text="结束日期查询"></asp:ListItem>
</asp:DropDownList>
</div>
<div>
<asp:TextBox ID="txtBottom" runat="server"></asp:TextBox>
<asp:DropDownList ID="ddBottom" runat="server">
<asp:ListItem Value="" Text="请选择查询条件"></asp:ListItem>
<asp:ListItem Value="startDate" Text="开始日期查询"></asp:ListItem>
<asp:ListItem Value="customer" Text="客户名称查询"></asp:ListItem>
<asp:ListItem Value="billType" Text="单据类别查询"></asp:ListItem>
<asp:ListItem Value="sales" Text="业务人员查询"></asp:ListItem>
<asp:ListItem Value="billNumber" Text="单号查询"></asp:ListItem>
<asp:ListItem Value="billState" Text="单据结/未结束状态查询"></asp:ListItem>
<asp:ListItem Value="endDate" Text="结束日期查询"></asp:ListItem>
<asp:ListItem Value ="cusCancle" Text="客户取消维修查询"></asp:ListItem>
</asp:DropDownList>
</div>
<div>
<asp:Button ID="btnQuery" runat="server" Text="查 询"/>
</div>
<div>
<asp:Repeater ID="rtResult" runat="server">

</asp:Repeater>
...全文
251 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuanmeixiang 2011-03-03
  • 打赏
  • 举报
回复
呵呵!!! 应该比较简单的
skating318 2011-03-03
  • 打赏
  • 举报
回复
今天刚注册,没法发帖
刚学asp.net 借楼问个简单问题
DROPDOWNLIST 如何实现 下拉 选择范围 输入关键字 然后搜索?
假设 数据库是A 表是B
刚学,需要详细点的代码:)
感谢先!
wuyq11 2011-03-02
  • 打赏
  • 举报
回复

string sql="select * from table where 1=1";
sql+=this.DropDownList1.SelectedValue!=null?" and 列='" + this.DropDownList1.SelectedValue+"'":""
sql+=this.DropDownList1.SelectedValue!=null?" and 列='" + this.DropDownList2.SelectedValue + "'":"";
子夜__ 2011-03-02
  • 打赏
  • 举报
回复
正好昨天给另以为朋友做的DEMO

 DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Gvbing();

}
}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.DropDownList1.SelectedValue != null)
{
dt = ReturnDataTable("select * from table where 列='" + this.DropDownList1.SelectedValue + "'");
}
else
{
dt = ReturnDataTable("select * from table");
}
Gvbing();
}

protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.DropDownList2.SelectedValue != null && this.DropDownList1.SelectedValue != null)
{
dt = ReturnDataTable("select * from table where 列='" + this.DropDownList1.SelectedValue + "' and 列='" + this.DropDownList2.SelectedValue + "'");
}
else if (this.DropDownList2.SelectedValue == null && this.DropDownList1.SelectedValue != null)
{
dt = ReturnDataTable("select * from table where 列='" + this.DropDownList1.SelectedValue + "'");
}
else
{
dt = ReturnDataTable("select * from table");
}
Gvbing();
}
public void Gvbing()
{
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}

/// <summary>
/// 执行有参的查询 返回DataTable
/// </summary>
/// <returns>返回DataTable</returns>
public static DataTable ReturnDataTable(string cmdtext)
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "数据库连接字符串";
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd = new SqlCommand(cmdtext, cn);
cmd.CommandType = CommandType.Text; ;
SqlDataReader dr = null;
using (dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
dt.Load(dr);
}
return dt;
}
mangchao330688 2011-03-02
  • 打赏
  • 举报
回复
楼上正解。
jekyshi 2011-03-02
  • 打赏
  • 举报
回复
string sql="select * from tableName where 1=1 "
if(a!="")
{
sql+=" and a='"+a+"'";
}
if(b!="")
{
sql+=" and b='"+b+"'";
}
……
……
……
zhongweng 2011-03-02
  • 打赏
  • 举报
回复
查询按钮的单击事件中得到两个DropDownList选中的值就行了啊 ddTop.selectValue

62,244

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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