2015-06-21 32 views
0

我在ASP.net C#前端和Oracle 11g後端創建了一個網頁。 網頁由2個DropDownList,按鈕和GridView組成。在這2個DropdownLists中,DropDownList1包含通過ListItem集合編輯器添加的靜態值「QC Released」,其他DropDownList2與數據庫綁定。 但是,在DropDwonList2中,我添加了通過ListItem集合編輯器添加的「ALL」項。當綁定到數據庫並手動添加項目時,DropDownList無法正常工作

現在,當我運行網頁並從DropDownList1中選擇「QC Released」和DropDownList2中除「ALL」以外的任何項時,我都會在GridView中得到結果。 但是,當我從DropDownList1中選擇「QC Released」並且DropDownList2中的「ALL」在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; 
    } 
} 

回答

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

這種情況從來沒有工作。試試看:

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

需要澄清的東西....我有DropDownList1即「QC發佈」 3項,「QC掛起」和「生產預訂」 ......現在這會是怎樣的狀況? –

+0

你的解決方案工作,但是當我選擇「質量待定」和「所有」得到沒有記錄,因爲它是在階梯如果....這意味着如果(DropDownList1.Text ==「QC發佈」&& DropDownList2.Text ==「 (DropDownList1.Text ==「QC Released」){} (DropDownList1.Text ==「QC Pending」&& DropDownList2.Text ==「ALL」){} –

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; 
      } 
     } 
相關問題