开发者

if grid has no records means it should say "no record found" without checking the database.how?

开发者 https://www.devze.com 2023-01-30 16:38 出处:网络
protected void btnedit_Click1(object sender, EventArgs e) { dt = (DataTable)ViewState[\"qualification\"];
 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();
                }
            }


        }
    }


GridView has property "EmptyDataText" it set the text if no data.

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

精彩评论

暂无评论...
验证码 换一张
取 消