仅在匹配ID匹配时显示gridview

时间:2016-01-12 05:46:26

标签: c# asp.net gridview

我在下拉列表中选择了一个与Project_idBuilding_idflat_id匹配的值的过滤器,然后 gridview应显示其他明智的

现在我想要的是如果所有 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();
}

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

protected void Button1_Click(object sender, EventArgs e)
    {
        if (ddl.SelectedIndex > 0)
        {
            int count = 0;
            int selectedcheckbox = 0;

            pfPL.Month = lblMonthId.Value;
            pfPL.Year = lblYear.Value;
         
            DataTable dt = pfBL.GetEmployeeCode(pfCPL);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (i < dt.Rows.Count - 1)
                    {

                        for (int k = 0; k < grd.Rows.Count; k++)
                        {
                            string grdcode;
                            Label lbl = (Label)grd.Rows[k].FindControl("lblCode");
                            grdcode = lbl.Text;
                            CheckBox chk = (CheckBox)grd.Rows[k].FindControl("chkone");
                            e;

                            dbcode = dt.Rows[i][0].ToString();
                            if (dbcode.Trim() == grdcode.Trim())
                            {
                                chk.Checked = true;
                                
                                count++;
                            }
                        }
                    }
                }
            }
            
        }
       
    }