user2994144
user2994144

Reputation: 167

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);
}

Upvotes: 0

Views: 617

Answers (3)

Ashish Gupta
Ashish Gupta

Reputation: 15139

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

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

Upvotes: 1

Tony
Tony

Reputation: 1307

You forget to add OnRowCommand to the GridView.

Upvotes: 1

voddy
voddy

Reputation: 1000

For your last question; Try using

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

Upvotes: 0

Related Questions