绑定到数据库并手动添加项目时,DropDownList无法正常工作

时间:2015-06-21 10:56:53

标签: asp.net c#-4.0 drop-down-menu oracle11g

我在ASP.net C#前端和Oracle 11g后端创建了一个网页。 网页由2个DropDownList,按钮和GridView组成。在这2个DropdownLists中,DropDownList1包含静态值" QC Released"通过ListItem Collection Editor和其他DropDownList2添加到数据库。 但是,在DropDwonList2中,我添加了" ALL"通过ListItem集合编辑器添加的项目。

现在,当我运行网页并选择" QC Released"来自DropDownList1和除" ALL"之外的任何项目。从DropDownList2我得到GridView中的结果。 但是当我选择" QC Released"来自DropDownList1和" ALL"从DropDownList2获取GridView中的任何数据,尽管有这个特定查询的数据。

请参考我的代码,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OracleClient;
using System.Data;
using System.Configuration;
using System.Drawing;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
DataSet ds = new DataSet();
OracleConnection con = new OracleConnection("Data Source=10.31.41.103/ORCL;User ID=RL_PET;Password=RL_PET;Unicode=True");

protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click1(object sender, EventArgs e)
{
    Label1.Visible = false;
    if (DropDownList1.Text == "QC Released")
    {

        con.Open();
        OracleDataAdapter a = new OracleDataAdapter("SELECT PALLET_NO, DATA_STS, MERGE, PLANT_CD, RELEASE_NO,RELEASE_DATE,QC_STATUS FROM WI_PALLET WHERE MERGE = '" + DropDownList2.Text + "' AND TRANS_TYPE = 'P' AND PLANT_CD IN ('39HV','39HF') AND DATA_STS <>9 AND DATA_STS IS NOT NULL AND PALLET_NO NOT LIKE '7%' ORDER BY PALLET_NO ASC", con);
        a.Fill(ds);
        if (ds.Tables[0].Rows.Count > 0)
        {
            int count = ds.Tables[0].Rows.Count;
            Label1.Text = count.ToString();
            Label1.Visible = true;
            GridView1.DataSource = ds;
            GridView1.DataBind();
            GridView1.Visible = true;
            con.Close();
        }
        else
        {
            Response.Write("<script>alert('No such Record Found')</script>");
            GridView1.Visible = false;
        }

    }
    else if (DropDownList1.Text == "QC Released" && DropDownList2.Text == "ALL")
    {
        con.Open();
        OracleDataAdapter a = new OracleDataAdapter("SELECT PALLET_NO, DATA_STS, MERGE, MFG_DT, PLANT_CD, RELEASE_NO, RELEASE_DATE, QC_STATUS FROM WI_PALLET WHERE TRANS_TYPE= 'P' AND PLANT_CD IN ('39HV','39HF') AND DATA_STS IS NOT NULL AND PALLET_NO NOT LIKE '7%'  ORDER BY PALLET_NO ASC", con);
        a.Fill(ds);
        if (ds.Tables[0].Rows.Count > 0)
        {
            int count = ds.Tables[0].Rows.Count;
            Label1.Text = count.ToString();
            Label1.Visible = true;
            GridView1.DataSource = ds;
            GridView1.DataBind();
            GridView1.Visible = true;
            con.Close();
        }
        else
        {
            Response.Write("<script>alert('No such Record Found')</script>");
            GridView1.Visible = false;
        }
    }
else
    {
        Response.Write("<script>alert('No such Record Found')</script>");
        GridView1.Visible = false;
    }
} 

2 个答案:

答案 0 :(得分:0)

else if (DropDownList1.Text == "QC Released" && DropDownList2.Text == "ALL")

这种情况永远不会奏效。试试这个:

if (DropDownList1.Text == "QC Released" && DropDownList2.Text == "ALL") {}
else if (DropDownList1.Text == "QC Released") {}

答案 1 :(得分:0)

我不确定您在查询构建中如何使用条件。试试这个。

if (DropDownList2.Text == "ALL")
        {
            switch (DropDownList1.Text)
            {
                case "QC Released": break;
                case "QC Pending": break;
                case "Production Booked": break;
            }
        }
        else
        {
            switch (DropDownList1.Text)
            {
                case "QC Released": break;
                case "QC Pending": break;
                case "Production Booked": break;
            }
        }