[英]Refresh gridview data with response redirect
The print button in below grid view it opens print page in new tab. 网格视图下方的打印按钮可在新选项卡中打开打印页面。
Using this java-script code. 使用这个java脚本代码。
Java Script Java脚本
<script type="text/javascript">
function SetTarget() {
document.forms[0].target = "_blank";
}
</script>
Also the print button updates OrderStatus
from 'Pending' to 'Received' 此外,打印按钮将
OrderStatus
从“待定”更新为“已接收”
The problem is when i press the print button in the grid data is not refreshed i have to reload the page to see that OrderStatus
has been changed to the updated value. 问题是,当我按下网格中的打印按钮数据未刷新时,我必须重新加载页面以查看
OrderStatus
已更改为更新的值。
Behind-Code 幕后码
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);
}
}
Grid Is Inside UpdatePanel 网格在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>
In your case update panel can't understand that there was change in data to update. 在您的情况下,更新面板无法理解要更新的数据发生了变化。 Therefore you need to update it manually.
因此,您需要手动更新它。 You can do this by calling
你可以通过电话来做到这一点
UpdatePanelName.Update();
in appropriate location like this: 在适当的位置,如下所示:
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");
}
Notice that you should change UpdatePanelName
with your own update panels name. 请注意,您应该使用自己的更新面板名称更改
UpdatePanelName
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.