如果网格没有记录意味着它应该在没有检查数据库的情况下说“没有找到记录”。

时间:2010-12-16 09:07:48

标签: asp.net c#-4.0

 protected void btnedit_Click1(object sender, EventArgs e)
    {

        dt = (DataTable)ViewState["qualification"];
        int Id;
        foreach (GridViewRow row in gvqualification.Rows)
        {
            RadioButton rb = (RadioButton)row.FindControl("rdoselect");
            HiddenField HFI = (HiddenField)row.FindControl("autoid");
            HiddenField HFE = (HiddenField)row.FindControl("qualificationid");
            Label lbleducational = (Label)row.FindControl("lbgeducationallevel");
            Label lblcollege = (Label)row.FindControl("lbgcollege");
            Label lbluniversity = (Label)row.FindControl("lbguniversity");
            Label lblspecialization = (Label)row.FindControl("lbgspecialization");
            Label lblscore = (Label)row.FindControl("lbgscore");
            Label lblstartyear = (Label)row.FindControl("lbgstartyear");
            Label lblyearofcompletion = (Label)row.FindControl("lbgyearofcompletion");
            Label lblstate = (Label)row.FindControl("lbgstate");
            Label lblcountry = (Label)row.FindControl("lbgcountry");


            if (rb.Checked)
            {
                Id = int.Parse(HFI.Value);
                hqualificationid.Value = HFE.Value;
                txteducationallevel.Text = lbleducational.Text;
                txtcollegename.Text = lblcollege.Text;
                txtuniversity.Text = lbluniversity.Text;
                txtspecialization.Text = lblspecialization.Text;
                txtscore.Text = lblscore.Text;
                ddlstartyear.Text = lblstartyear.Text;
                ddlyearofcompletion.Text = lblyearofcompletion.Text;
                txtstate.Text = lblstate.Text;
                txtcountry.Text = lblcountry.Text;
                dt = (DataTable)ViewState["qualification"];
                int index = -1;
                try
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        index = index + 1;
                        if (dr["ID"].ToString() == Id.ToString())
                        {
                            dt.Rows[index].Delete();
                            ViewState["qualification"] = dt;
                            btnremove.Visible = false;
                        }
                    }
                }
                catch (Exception E)
                {
                    dt = (DataTable)ViewState["qualification"];
                    gvqualification.DataSource = dt;
                    gvqualification.DataBind();
                }
            }


        }
    }

1 个答案:

答案 0 :(得分:1)

GridView具有属性“EmptyDataText”,如果没有数据则设置文本。

<asp:GridView ID="grid" runat="server" EmptyDataText="No Record Found!" >
<column> --- </column>
</asp:GridView>