【发布时间】:2014-08-08 14:22:09
【问题描述】:
当我单击“关机”按钮时,它会发送一条消息,并且我也收到了可以在 DataTable 中验证的响应。但是 DataGrid 没有被填充。我检查了 DataGrid 的 Rows 属性,它有行,但是页面不显示结果。
这是我的代码:
BasicControls.aspx 页面
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<%-- asp:AsyncPostBackTrigger ControlID="UpdateTimer" EventName="Tick" />--%>
</Triggers>
<ContentTemplate>
<div id="cmdResultsgrdView">
<asp:GridView ID="grdMessage" runat="server" AutoGenerateColumns="true">
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ListenerTimer" EventName="Tick" />
</Triggers>
<ContentTemplate>
.aspx.cs 文件
{
private static Action<List<IMessage>> callBackCommandResponse = null;
//ctor
public BasicControls()
{
callBackCommandResponse = CommandResponse;
}
//Callback Method
public void CommandResponse(List<IMessage> Message)
{
//Based on MsgType we will filter and display the response.
if (null != Message)
{
//2. Call GetMessage to filter and process message and return DataTable
resultsDataTable = GetMessages(Message);
//3. Populate the Grid binding to DataTable
grdMessage.DataSource = resultsDataTable;
grdMessage.DataBind();
}
}
//receiver constructor in which we are passing callback to be populated.
private ReceivePM receiver = new ReceivePM(callBackCommandResponse);
//On clicking the code sends Shutdown Command to message queue.
protected void btnShutdown_Click(object sender, EventArgs e)
{
SenderInformation cmdSender = new SenderInformation();
cmdSender.SendShutdownCommand();
}
}
【问题讨论】:
-
Gridview 在 UpdatePanel1 里面,并且 UpdateMode 是“Conditional”,那么你需要在后面的代码中手动调用 Update() 方法。尝试在 DataBind() 事件后调用“UpdatePanel1.Update()”方法。
标签: c# asp.net datagrid datatable