views:

130

answers:

1

how can I check if my SqlDataSource1 select method returns 0 count of nodes (rows) after :

SqlDataSource1.DataBind();
+1  A: 

If I understand your comment, what you want to do is check the gridview after you databind for any rows, if there is not any it will just return zero (0)

GridView1.DataBind();
int i = 0;
i = GridView1.RowCount;

EDIT after comments: OK, now I understand.here is how you can check the datasource for the number of records affected, you have to use the SqlDataSource1_Selected event

protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
    if (e.AffectedRows > 0) //this is where you check the number of rows!
    {
        //do something
    }
    else
    {
        //something else...
    }
} 

The selected event fires right after the select operation completes

curtisk
but I can't check GridView on this step (only after DataBound) but OnDataBount Method will not be called after I do SqlDataSource1.DataBind(); if there will be no data to Bound. .NET somehow knows if there a Data or a EOF , I want to know it too )
nCdy
yes . Thank you . That's what I really wanted )
nCdy
no problem, you're welcome!
curtisk
No :) That doesn't helps, because it Select method will be called after page render and this method returns old data, for example if there was no data and I click button for data there will No Data warning from old statement. and also I dont think that double render is good idea :S
nCdy