在ASPX页面中有两个DataGrid控件。设置数据源并调用DataBind()后,第一个控件将填充。但是,第二个控件不呈现数据。
这是标记:
<!--First DataGrid-->
<asp:DataGrid ID="dgPremiumHistory" runat="server" AutoGenerateColumns="false" OnItemCommand="dgPremiumHistory_ItemCommand" DataKeyField="ID">
<Columns>asp:BoundColumn HeaderText="Company Premium History ID" DataField="ID" ReadOnly="True" Visible="False" />
<asp:BoundColumn HeaderText="Premium Year" DataField="PremiumYear" ReadOnly="True" />
<asp:BoundColumn HeaderText="Amount" DataField="Amount" ReadOnly="True" />
<asp:ButtonColumn ButtonType="PushButton" Text="Edit" CommandName="EditPremium" /></Columns></asp:DataGrid>
<!--Second DataGrid-->
<asp:DataGrid ID="dgPayrollHistory" runat="server" AutoGenerateColumns="false" OnItemCommand="dgPayrollHistory_ItemCommand" DataKeyField="ID">
<Columns><asp:BoundColumn HeaderText="Company Payroll History ID" DataField="ID" ReadOnly="True" Visible="False" />
<asp:BoundColumn HeaderText="Payroll Year" DataField="PayrollYear" ReadOnly="True" /><asp:BoundColumn HeaderText="Amount" DataField="Amount" ReadOnly="True" />
<asp:ButtonColumn ButtonType="PushButton" Text="Edit" CommandName="EditPayroll" /></Columns></asp:DataGrid>
C#代码隐藏:
protected void PopulateDgPremiumHistory(ref DataTable dt)
{
dgPremiumHistory.DataSource = dt;
dgPremiumHistory.DataBind();
}
protected void PopulateDgPayrollHistory(ref DataTable dt)
{
dgPayrollHistory.DataSource = dt;
dgPayrollHistory.DataBind();
}
我正在调用Page_Load事件中的方法。任何帮助表示赞赏。
谢谢!
if (!Page.IsPostBack)
{
dt = new DataTable();
dt = pkg.getCompanyPremiumHistory(hfWCAppID.Value);
PopulateDgPremiumHistory(ref dt);
dt = new DataTable();
dt = pkg.getCompanyPayrollHistory(hfWCAppID.Value);
PopulateDgPayrollHistory(ref dt);
}
答案 0 :(得分:0)
对于任何有兴趣的人,我不得不使用解决方法。将DataGrid控件放在单独的Panel控件中。使用按钮单击事件,我显示/隐藏了面板,同时调用相应的方法来填充DataGrid。