网格视图下方的打印按钮,它会在新标签页中打开打印页面。
使用此java脚本代码。
Java脚本
<script type="text/javascript">
function SetTarget() {
document.forms[0].target = "_blank";
}
</script>
此外,打印按钮会将OrderStatus
从“待处理”更新为“已收到”
问题是,当我按下网格中的打印按钮数据未刷新时,我必须重新加载页面才能看到OrderStatus
已更改为更新后的值。
幕后代码
protected void gridOrders_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
string commandName = e.CommandName.ToString().Trim();
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
GridViewRow gvRow = (GridViewRow)((Control)e.CommandSource).NamingContainer;
Int32 rowind = gvRow.RowIndex;
string orderid = row.Cells[1].Text;
switch (commandName)
{
case "Print":
if (r.CheckReceiving(orderid))
{
Session["orderid"] = orderid;
Server.Transfer("OrderPrint.aspx");
}
else
{
string msg = r.AddReceiving(r.GetNextReceivingID(), orderid, DateTime.Now.ToString());
if (msg == "true")
{
o.UpdateOrderStatus(orderid, "Received");
gridOrders.DataSource = o.ManageOrders(UtilityClass.ReadFromCookie("login", "OutletD", Request));
gridOrders.DataBind();
Session["orderid"] = orderid;
Server.Transfer("OrderPrint.aspx");
}
else
{
divreceivedfalse.Visible = true;
}
}
break;
default: break;
}
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
}
网格在UpdatePanel内
<asp:GridView ID="gridOrders" OnRowDataBound="gridOrders_RowDataBound" OnRowCommand="gridOrders_RowCommand" runat="server" CssClass="table table-bordered text-nowrap" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Print" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="SetTarget('_blank');" CommandName="Print" CausesValidation="False" CssClass="btn btn-primary btn-xs" Text=""><i class="glyphicon glyphicon-print"></i></asp:LinkButton>
</ItemTemplate>
<ControlStyle CssClass="btn btn-default " />
</asp:TemplateField>
<asp:BoundField DataField="OrderID" HeaderText="Order #" SortExpression="OrderID" />
<asp:BoundField DataField="OrderDate" DataFormatString="{0:dd/MMM/yyyy hh:mm tt}" HeaderText="Order Date" SortExpression="OrderDate" />
<asp:TemplateField HeaderText="Status" SortExpression="Status">
<ItemTemplate>
<asp:Label ID="lblStatus" CssClass="label label-primary" runat="server" Text='<%# Bind("OrderStatus") %>'> CausesValidation="False" Text=''></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
答案 0 :(得分:0)
在您的情况下,更新面板无法理解要更新的数据发生了变化。因此,您需要手动更新它。你可以通过调用
来做到这一点UpdatePanelName.Update();
在适当的位置,如:
if (msg == "true")
{
o.UpdateOrderStatus(orderid, "Received");
gridOrders.DataSource = o.ManageOrders(UtilityClass.ReadFromCookie("login", "OutletD", Request));
gridOrders.DataBind();
UpdatePanelName.Update();
Session["orderid"] = orderid;
Server.Transfer("OrderPrint.aspx");
}
请注意,您应该使用自己的更新面板名称更改UpdatePanelName
。