2016-01-12 86 views
0

當我已經施加在下拉列表中選擇值的過濾器相匹配的Project_idBuilding_idflat_id然後gridview的應顯示其他明智不顯示gridview的匹配ID的匹配

現在我想要的是,如果所有的ID匹配,那麼只顯示gridview。

這裏是我下面的代碼: -

DataTable dt = new DataTable(); 

    dt.Columns.Add("PROJECT_ID"); 
    dt.Columns.Add("BUILDING_ID"); 
    dt.Columns.Add("FLAT_ID"); 

    DataView dView = new DataView(dt); 

    dView.RowFilter = "PROJECT_ID = " + ddlProject.SelectedValue + " AND BUILDING_ID = " + ddlBuilding.SelectedValue + " AND FLAT_ID = " + ddlUnit.SelectedItem.Text; 
    GrdBookingStatus.DataSource = dView.ToTable(); 
    GrdBookingStatus.DataBind(); 

    DisplayGrid(); 
    GrdBookingStatus.Visible = true; 

目前它顯示,如果ID的不匹配也

我應該檢查什麼條件?

DisplayGrid()

protected void DisplayGrid() 
{ 
    OracleCommand cmd = new OracleCommand("SELECT pn.property_name, pn.building, cd.flat_id, ab.flat_status, ab.COMMENTS " + 
              "FROM xxcus.xxacl_pn_projbuild_v pn INNER JOIN xxacl_pn_flat_status_his ab " + 
              "ON pn.project_id = ab.project_id AND pn.building_id = ab.building_id " + 
              "INNER JOIN xxacl_pn_flat_det_v cd ON cd.flat_id = ab.flat_id", ObjPriCon); 
    DataTable dtfillgrid = new DataTable(); 
    OracleDataAdapter da = new OracleDataAdapter(cmd); 
    da.Fill(dtfillgrid); 
    GrdBookingStatus.DataSource = dtfillgrid; 
    GrdBookingStatus.DataBind(); 
} 
+0

爲什麼既'PROJECT_ID'和'BUILDING_ID'由'SelectedValue'檢查? –

+0

@AlexJolig:因爲在'db'中,它的值被保存了,而'flat',它就是以'Text'的形式出現,這就是原因。 – BNN

+0

你爲什麼要再次調用'DisplayGrid();'?它究竟做了什麼? – Irshad

回答

1

DisplayGrid()方法返回你有過濾器並顯示所有數據。

移動DisplayGrid()方法內的過濾器。

protected void DisplayGrid() 
{ 
    OracleCommand cmd = new OracleCommand("SELECT pn.project_id AS project_id, pn.property_name, pn.building, pn.building_id AS building_id, cd.flat_id AS flat_id, ab.flat_status, ab.COMMENTS " + 
              "FROM xxcus.xxacl_pn_projbuild_v pn INNER JOIN xxacl_pn_flat_status_his ab " + 
              "ON pn.project_id = ab.project_id AND pn.building_id = ab.building_id " + 
              "INNER JOIN xxacl_pn_flat_det_v cd ON cd.flat_id = ab.flat_id", ObjPriCon); 
    DataTable dtfillgrid = new DataTable(); 
    OracleDataAdapter da = new OracleDataAdapter(cmd); 
    da.Fill(dtfillgrid); 

    DataView dView = new DataView(dtfillgrid); 

    dView.RowFilter = "PROJECT_ID = " + ddlProject.SelectedValue + " AND BUILDING_ID = " + ddlBuilding.SelectedValue + " AND FLAT_ID = " + ddlUnit.SelectedItem.Text; 
    GrdBookingStatus.DataSource = dView.ToTable(); 
    GrdBookingStatus.DataBind(); 
    GrdBookingStatus.Visible = dView.ToTable().Rows.Count > 0; 
} 

我也修改您SELECT語句返回pn.project_idpn.building_id

+0

我想在第三個下拉列表的'selectedindexchanged'事件上顯示網格。 – BNN

+0

在'selectedindexchanged'事件中調用'DisplayGrid()'。 – Irshad

+0

因'找不到列'PROJECT_ID'錯誤而出錯 – BNN