网格视图 - 在按钮上绑定数据和数据源单击但不显示网格

时间:2014-03-10 09:17:33

标签: c# asp.net gridview

GridView中有UpdatePanel。在按钮单击事件上,我使用网格视图绑定数据。数据正在绑定,但Grid未显示。

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           bindData();
        }
    }

protected void bindData() 
        {
                    // dv is my data view have rows and columns
                    GridView1.DataSource = dv;
                    GridView1.DataBind();
                    UpdatePanel.Update();
                }
        }

按钮点击事件: -

protected void btnUpdateExtensions_Click(object sender, EventArgs e)
        {   
        // dv is data view have data with columns and rows
        GridView1.DataSource = dv;
        GridView1.DataBind();
                UpdatePanel.Update();      
        }

在页面加载其绑定数据时,正确显示GridView的广告,但在按钮Click Event中,当数据源来自同一来源时,它不显示GridView。

1 个答案:

答案 0 :(得分:1)

您的按钮位于updatepanel内,然后只需拨打

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
your button and gridview
</asp:UpdatePanel 

protected void btnUpdateExtensions_Click(object sender, EventArgs e)
        {   
         bindData();
        }

无需编写UpdatePanel.Update();

相关问题