开发者

How to show GridView during Page_Load?

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?


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


  If Not Page.IsPostBack Then
           btnView_Click(nothing,nothing)    
  End If

or

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜