views:

20

answers:

3

Hi all,

I have a gridview that normally loads when a user clicks a View Report button. However, I now want to show the gridview while the page loads.

I tried calling the following method from the Page_Load event:

   protected void btnView_Click(object sender, EventArgs e)
    {
        try
        {
            grvReport.DataBind();
        }
        catch (Exception ex)
        {
            Master.ShowMessage(ex.Message);
        }
    }

but it didn't work. Also tried calling grvReport.DataBind() from Page_Load to no avail.

Any suggestions?

A: 

This seems too obvious, but does the gridview have visible="true"

Lost in Alabama
A: 
  If Not Page.IsPostBack Then
           btnView_Click(nothing,nothing)    
  End If

or

If Not Page.IsPostBack Then
       grdNotes.DataSource = myDataSource
       grdNotes.DataBind()
End If
arlen
A: 

If you are binding to a null/empty DataSource...then the GridView will not show up. You probably need to set the EmptyDataText property to something so that you can at least display a message when there is nothing to bind to.

Dismissile