Validate grid rows before databind

2 posts, 0 answers
  1. Alex
    Alex avatar
    23 posts
    Member since:
    Dec 2012

    Posted 01 Apr 2013 Link to this post

    I have a RadGrid with 3 external filter controls: 1 textbox and 2 comboboxes. Things work well when the requested data from these controls is successfully returned by the GetData() query. However, if I try to return an incorrect value from one of the controls my app blows-up stating that I have no bindable data. How can I create a scenario from which it checks to see if my DataTable returns rows and if NOT, then display a pop-up message AND to not re-bind the RadGrid? Here is my current code ...
    My controls include: RadGrid1, RadComboBox1, RadComboBox2, RadTextBox1, DataTable = myDataTable, DataRows = rows.

    if (condition) {rows =...}
    else if (condition) {rows = ...}               
    else
    {
    return new DataTable();
    }
                     
    if (myDataTable.Rows.Count == 0)
    {
    ClientScript.RegisterStartupScript(this.GetType(), "norowalert", "alert('I cannot complete your request.\nThere are no records that meet your criteria.');", true);
    return new DataTable();
    }
    if (rows.Length == 0)
    {
    ClientScript.RegisterStartupScript(this.GetType(), "norowalert", "alert('I cannot complete your request.\nThere are no records that meet your criteria.');", true);
    return new DataTable();
                         
    }
     
    if (rows.Length >= 1)
    {
    return rows.CopyToDataTable();
    RadGrid1.DataBind();
    }
    return rows.CopyToDataTable();
    }
  2. Alex
    Alex avatar
    23 posts
    Member since:
    Dec 2012

    Posted 02 Apr 2013 Link to this post

    I had an answer posted on Experts-Exchange http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_28077563.html

    if (rows.Length == 0)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "norowalert", "alert('I cannot complete your request.');", true);
                        return myDataTable.Clone(); // returns a data table with ame columns and everything but no data
                    }

    Please mark 'answered'.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top