【发布时间】:2014-02-26 22:24:12
【问题描述】:
我有一个页面显示有关 Gridview 中项目的信息,当用户单击 ItemNo 时,它应该转到新的重定向页面。以下是我所拥有的,但它似乎不起作用。
它应该通过使用 ItemNo 从 Db 获取 ID 号,而不是将其自身重定向到适当的页面。
页面应重定向到具有不同 IP 地址和主机名的页面。
.aspx 页面
<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 页面
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);
}
【问题讨论】: