当我单击关机按钮时,它会发送一条消息,我也得到了响应,我可以在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();
}
}
答案 0 :(得分:0)
尝试调用&#34; UpdatePanel1.Update()&#34; DataBind()事件之后的方法。
grdMessage.DataSource = resultsDataTable;
grdMessage.DataBind();
UpdatePanel1.Update();
答案 1 :(得分:0)
谢谢大家。 但我想我的应用程序正在与之交互 队列。 所以,我没有使用ICallBackEventHandler,我实现了自己的回调并将Queue侦听器方法作为一个单独的任务而不是在计时器内启动。 如果您有自己的回调,则需要以下代码 if(resultsDataTable.Rows.Count&gt; 0) { grdMessage.DataSource = resultsDataTable; grdMessage.DataBind(); System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.IO.StringWriter sw = new System.IO.StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); grdMessage.RenderControl(HW);
}