DataList 命令无法重定向到另一个页面
DataList Command cannot redirect to another page
我遇到无法使用 DataList 命令重定向到另一个页面的问题。这是我的 aspx 代码。
<asp:DataList id="CategoryList"
OnItemCommand="Barcode_RowCommand"
BorderColor="black"
CellPadding="1"
CellSpacing="1"
RepeatDirection="Horizontal"
RepeatLayout="Table"
RepeatColumns="4"
BorderWidth="0"
runat="server" ItemStyle-HorizontalAlign="Center" ItemStyle-Font-Names="arial" ItemStyle-Font-Size="12px"
ItemStyle-ForeColor="#ffffff" style="margin-left:auto; margin-right:auto;">
我如何使用图像按钮处理命令
<asp:ImageButton ID="Add"
ImageUrl= '<%# "getImage.aspx?Barcode=" + Eval("Barcode") %>'
ForeColor="black"
runat="server"
Visible="true"
Width = "200px"
height ="170px"
CommandArgument='<%# Eval("Barcode")%>'
DataKeyField="Barcode"
CommandName="Add"></asp:ImageButton>
下面是我的 aspx.cs
代码
public void Barcode_RowCommand(Object sender, DataListCommandEventArgs e)
{
if (e.CommandName == "Add")
{
Response.Redirect("ProductDetail.aspx");
}
}
代码没有错误,但是当我单击图像按钮时,它不会将我重定向到 productdtail.aspx,而是在同一页面。任何帮助或建议将不胜感激。再次感谢
作为我的问题,我只是对以下代码做了一些更改
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ViewState["vs"] = 0;
pos = (int)this.ViewState["vs"];
databind2();
databind();
}
}
起初我的 databind2 和 databind 不在 if 语句中,我按照 this answer 将我的 databind2 和 databind 放入 if 语句中,我的问题就解决了。谢谢你的时间
我遇到无法使用 DataList 命令重定向到另一个页面的问题。这是我的 aspx 代码。
<asp:DataList id="CategoryList"
OnItemCommand="Barcode_RowCommand"
BorderColor="black"
CellPadding="1"
CellSpacing="1"
RepeatDirection="Horizontal"
RepeatLayout="Table"
RepeatColumns="4"
BorderWidth="0"
runat="server" ItemStyle-HorizontalAlign="Center" ItemStyle-Font-Names="arial" ItemStyle-Font-Size="12px"
ItemStyle-ForeColor="#ffffff" style="margin-left:auto; margin-right:auto;">
我如何使用图像按钮处理命令
<asp:ImageButton ID="Add"
ImageUrl= '<%# "getImage.aspx?Barcode=" + Eval("Barcode") %>'
ForeColor="black"
runat="server"
Visible="true"
Width = "200px"
height ="170px"
CommandArgument='<%# Eval("Barcode")%>'
DataKeyField="Barcode"
CommandName="Add"></asp:ImageButton>
下面是我的 aspx.cs
代码public void Barcode_RowCommand(Object sender, DataListCommandEventArgs e)
{
if (e.CommandName == "Add")
{
Response.Redirect("ProductDetail.aspx");
}
}
代码没有错误,但是当我单击图像按钮时,它不会将我重定向到 productdtail.aspx,而是在同一页面。任何帮助或建议将不胜感激。再次感谢
作为我的问题,我只是对以下代码做了一些更改
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ViewState["vs"] = 0;
pos = (int)this.ViewState["vs"];
databind2();
databind();
}
}
起初我的 databind2 和 databind 不在 if 语句中,我按照 this answer 将我的 databind2 和 databind 放入 if 语句中,我的问题就解决了。谢谢你的时间