简体   繁体   中英

response redirect url aspx page

I have a page that displays information about items in Gridview and when the user clicks the ItemNo than it should go to the new redirected page. The following is what I have and it doesn't seem to work.
It supposed to get the ID number from the Db by using the ItemNo than redirect it self to the appropriate page.

The page should redirect to a page that has a different IP address and host name.

.aspx page

<asp:GridView ID="gvWorkOrderSum" runat="server" CellPadding="4" 
ShowFooter="True" DataKeyNames="InfoID" BorderColor="#5D7B9D" BorderWidth="2px"  OnDataBound="gvWorkOrderSum_OnDataBound"
ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" OnRowDeleting="gvWorkOrderSum_RowDeleting"
Caption='<table width="100%" cellpadding="0" cellspacing="0" bgcolor="#5D7B9D"><tr><td ><span style="color: white; font-family: Arial Black">WorkOrder information</span></td></tr></table>'
DataSourceID="odsWorkOrderList">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns> 
<asp:TemplateField ShowHeader="False">

 <asp:TemplateField HeaderText="ItemNo">
 <HeaderStyle HorizontalAlign="Center" />
 <ItemStyle HorizontalAlign="Center" />
 <FooterStyle HorizontalAlign="Center" />
 <ItemTemplate>
 <asp:LinkButton ID="lbItemNo" runat="server" CommandName="OrderDetail" CommandArgument='<%#Eval("ItemNo") %>'
Text='<%# Bind("ItemNo") %>'></asp:LinkButton> 
</ItemTemplate>
</asp:GridView>

aspx.cs page

 protected void gvWorkOrderSum_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "OrderDetail")  //
{ 
int nItemNo = int.Parse(e.CommandArgument.ToString());
SqlCommand cmd = new SqlCommand("SELECT ID FROM Order_Items WHERE Item_ID =" + nItemNo);
cmd.Parameters.Add("@ID", SqlDbType.Int).Direction = ParameterDirection.Output;
InternalSalesDB.Instance.query(cmd);
Response.Redirect("Sales/Orders/OrderDetail.aspx?ID=" + (get the ID number from DB) + "&ItemNo=" + nItemNo, true);
}

您忘了将OnRowCommand添加到GridView

Use the OnRowCommand attribute on the GridView with the event handler gvWorkOrderSum_RowCommand

<asp:GridView ID="gvWorkOrderSum" OnRowCommand="gvWorkOrderSum_RowCommand" ...>
    ...
</asp:GridView>

For your last question; Try using

Response.Redirect("~\\Sales\Orders\OrderDetail.aspx?OID=" + (get the OID number from DB) + "&ItemNo=" + nItemNo, true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM