This is a migrated thread and some comments may be shown as answers.

Validate grid rows before databind

1 Answer 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 01 Apr 2013, 04:36 PM
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();
}

1 Answer, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 02 Apr 2013, 03:21 PM
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'.
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 1
Share this question
or