1

我是一名新手实习生,试图“修复”内部表单背后的 c# 代码。该代码使用我们数据库中的日期填充了几个数据网格。

如果其中一个网格返回没有行(有时会发生这种情况,它应该会发生),我想让几个导出按钮不可见。

当您单击 go 按钮填充网格时,如果某个网格返回没有行,则按钮应该变得不可见;

然而它不起作用!

我发布了整个按钮单击事件以获取上下文,但我对按钮的尝试是在最底部(出于安全原因,一些识别内容已在代码中删除)。

我究竟做错了什么?

public void btn_go_Click(object sender, EventArgs e)
{
    try
    {
        string site = this.ddl_site.SelectedValue;
        string srn = this.ddl_al.SelectedValue;

        int siteID = Common.CommonFunctions.XXXXXX_SiteID(site);

        using (DBML.XXXXDataContext db = AuthUtils.Auth.getDataContext(Common.DataContextE.XXXXX, Common.CommonFunctions.getXXXXX_ServerFromString(site)))
        {

            var CHAL = (from gal in db.XXXXXXXAccessLevels
                        where gal.ServerID.Equals((short)siteID)
                        && gal.ServerRecordNumber.ToString().Equals(srn)

                        select gal.XXXXXccessLevels.FirstOrDefault());
            if (CHAL.First() == null)
            {
                throw new Exception("No corresponding CHAL for this GAL [SiteID=" + siteID + ",SRN=" + srn + "]");
            }

            BaseClasses.XXXXXXX_AccessLevel al = new BaseClasses.XXXXXXX_AccessLevel(CHAL.FirstOrDefault());

            this.lbl_al_tag.Text = "Access Level Name: ";
            this.lbl_al_name.Text = al.AccessLevelName;
            this.lbl_al_desc_tag.Text = "Access Level Descr: ";
            this.lbl_al_desc.Text = al.AccessLevelDesc;

            this.gv_people.DataSource = al.getPeople();
            this.gv_people.RowDataBound += new GridViewRowEventHandler(gv_people_RowDataBound);

            this.gv_people.DataBind();

            this.gv_doors.DataSource = al.getDoors();

            this.gv_doors.RowDataBound += new GridViewRowEventHandler(gv_doors_RowDataBound);

            this.gv_doors.DataBind();

            this.gv_doors.Visible = true;
            this.gv_people.Visible = true;
            this.lbl_al_name.Visible = true;
            this.lbl_al_desc.Visible = true;

            //attempt to hide export buttons for 
            ////Working on this right here
            int rowCount = this.gv_doors.Rows.Count;
            if (rowCount > 0)
            {
                export_excel.Visible = true;
                export_excell_both.Visible = true;
            }
            else
            {
                export_excel.Visible = false;
                export_excell_both.Visible = false;

            }




        }
    } 
4

1 回答 1

0

如果您尝试使用int rowCount = al.getDoors().Count而不是网格的行数?当您尝试访问它们时,网格行数可能尚未更新。

于 2013-09-20T14:34:03.330 回答