SqlDataSource1 empty?

  • Thread starter Thread starter Mr. SweatyFinger
  • Start date Start date
M

Mr. SweatyFinger

I have a gridview with a sqldatasource going to a sql server.
I have a lot of conditional-displayed placeholders
how do i tell if the gridview comes up with no records before the page
loads, so I don't get an error?
 
Hi Mr. Sweety,

1. If Page is displayed by the first time (IsPostBack == false)
You cannot access this information on page load because SqlDataSource
retrieves its data on PreRender, but you can see if there are any records
handling gridview's DataBound event:

protected void GridView1_DataBound(object sender, EventArgs e)
{
GridView gridView = (GridView)sender;
bool hasResults = gridView.Rows.Count;
}

2. Page is posted back (IsPostBack == false) and viewstate is enabled:
(simplifying) data is not bound, items are restored from viewstate in
page_init (which occurs before Page_load) so you may test for emptiness.

In addition to that, there are many events you could handle in SqlDataSource
: i.e. Selected, Selecting etc.

Hope this helps

Milosz
 
Back
Top