Thursday, 20 February 2014

ASP.NET Clear the GridView data on specific condition

ASP.NET Clear the GridView data on specific condition

When there are no data found for user search criteria then we want to clear the previous gridview data and display "No record found" message to user.

This can be achieved by following line of code:
Set the DataSource = null and bind this to your gridview.



if (lblError.Visible == false)
                {
                    if (dvCustomerRecords.Count > 0)
                    {
                        gvCustomer.DataSource = dvCustomerRecords;
                    }
                    else
                    {
                        gvCustomer.DataSource = null;
                        lblError.Visible = true;
                        lblError.Text = "No Record : No record found for specified search criteria!";
                    }
                }

                gvCustomer.DataBind();

No comments:

Post a Comment