我有一个gridview,通常在用户点击View Report按钮时加载。但是,我现在想在页面加载时显示gridview。
我尝试从Page_Load事件调用以下方法:
protected void btnView_Click(object sender, EventArgs e)
{
try
{
grvReport.DataBind();
}
catch (Exception ex)
{
Master.ShowMessage(ex.Message);
}
}
但它不起作用。还尝试从Page_Load调用grvReport.DataBind()
无效。
有什么建议吗?
答案 0 :(得分:0)
这看起来太明显了,但gridview有可见=“true”
答案 1 :(得分:0)
If Not Page.IsPostBack Then
btnView_Click(nothing,nothing)
End If
或
If Not Page.IsPostBack Then
grdNotes.DataSource = myDataSource
grdNotes.DataBind()
End If
答案 2 :(得分:0)
如果绑定到null / empty DataSource ...那么GridView将不会显示。您可能需要将EmptyDataText属性设置为某样,以便在没有任何要绑定的内容时至少可以显示消息。