【问题标题】:DataList Command cannot redirect to another pageDataList 命令无法重定向到另一个页面
【发布时间】:2015-12-11 06:06:46
【问题描述】:

我遇到了无法使用 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,而是在同一页面上。任何帮助或建议将不胜感激。再次感谢

【问题讨论】:

  • 1.产品详细信息的 page_load 代码是什么?您是否在事件处理程序的 if 块处设置了断点? response.redirect 行被执行了吗?
  • 在 Response.Redirect 中放置一个断点并检查给定的路径。
  • @SatyakiChatterjee 我还没有放任何产品细节的代码,我会放断点看看
  • 感谢您抽出宝贵时间@SatyakiChatterjee,我解决了我的问题。
  • 别忘了@rajeeshmenoth

标签: c# webforms datalist


【解决方案1】:

作为我的问题,我只是对以下代码进行了一些更改

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 语句中,我的问题就解决了。感谢您的宝贵时间

【讨论】:

    猜你喜欢
    • 2015-04-24
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    相关资源
    最近更新 更多