-3
 Dim objItems As clsItems

'Loads the pages with the Gridview and Infomation pretaining to the Item selected
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

    Dim qryItemNum As String = Request.QueryString("qryItemNum")

    'Populates Gridview
    If Not Page.IsPostBack Then
        gvwCategorySelect.DataSource = clsCategory.GetList
        gvwCategorySelect.DataBind()

        'imgbtnPrev.Visible = False

        'If Not String.IsNullOrEmpty(qryItemNum) Then
        '    Dim ItemNum As Int32
        '    If Int32.TryParse(test, ItemNum) Then
        '        imgbtnPrev.Visible = (-1 < ItemNum)
        '    End If
        'End If
    End If


    objItems = New clsItems(qryItemNum)

    'Set up the from labels
    lblTitle.Text = objItems.Title
    lblPrice.Text = objItems.Price.ToString("C")
    lblDescription.Text = objItems.Description
    ImgItem.ImageUrl = "~/images/ItemImages/Item" & objItems.ItemNum & ".jpg"



End Sub

'Returns to pervious item
Protected Sub imgbtnPrev_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles imgbtnPrev.Click

    Response.Redirect("~/ItemInfo.aspx?qryItemNum=" & objItems.ItemNum - 1)

End Sub

'Next item
Protected Sub imgbtnNext_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles imgbtnNext.Click


    Response.Redirect("~/ItemInfo.aspx?qryItemNum=" & objItems.ItemNum + 1)

End Sub

在上面的代码中有 2 个图像按钮,它们在不同的 ItemNum 之间移动。我试图通过在查询字符串为 1 时删除 imgbtnPrev 按钮来阻止用户单击上一个按钮。

错误消息显示位置 0 处没有行

dataRowObject = DBMethods.CreateTable(sqlString, sqlArg).Rows(0)

^ 这里是突出显示的地方。

4

2 回答 2

1

尝试这个

   int number;
   if(Request.QueryString["qryItemNum"]!= null)
    {
     bool isNumeric = int.TryParse(Request.QueryString["qryItemNum"].ToString(), out number);
      if(isNumeric == true)
      {
        if(Convert.ToInt(Request.QueryString["qryItemNum"])<=1)
        {
          imgbtnPrev = false;
        }
      }
   }

编辑: 我将其转换为 VB.NET

   Dim number As Integer
   If Request.QueryString("qryItemNum") IsNot Nothing Then
Dim isNumeric As Boolean = Integer.TryParse(Request.QueryString("qryItemNum").ToString(), number)
   If isNumeric = True Then
    If Convert.ToInt(Request.QueryString("qryItemNum")) <= 1 Then
        imgbtnPrev = False
    End If
   End If
   End If
于 2013-03-01T20:14:12.547 回答
1

我认为这就是VB的做法:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
        imgbtnPrev = False
        Dim qryItemNum As String = Request.QueryString("qryItemNum")
        If Not String.IsNullOrEmpty(qryItemNum) Then
          Dim ItemNum As Int32
          If Int32.TryParse(qryItemNum, ItemNum) Then
            imgbtnPrev = (-1 < ItemNum)
          End If
        End If
    End If
End Sub

当然,这假定它imgbtnPrev是在您的代码或 ASPX 页面中的某处定义的。

编辑:从您的评论之一imgbtnPrev.Visible = False到您的原始问题,它似乎imgbtnPrev是您表单上的一个按钮。如果是这种情况,您将编写如下内容:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
        imgbtnPrev.Visible = False
        Dim qryItemNum As String = Request.QueryString("qryItemNum")
        If Not String.IsNullOrEmpty(qryItemNum) Then
          Dim ItemNum As Int32
          If Int32.TryParse(qryItemNum, ItemNum) Then
            imgbtnPrev.Visible = (-1 < ItemNum)
          End If
        End If
    End If
End Sub

EDIT2:此版本使用Try...Catch来查看错误是什么:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
        imgbtnPrev.Visible = False
        Try
          Dim qryItemNum As String = Request.QueryString("qryItemNum")
          If Not String.IsNullOrEmpty(qryItemNum) Then
            Dim ItemNum As Int32
            If Int32.TryParse(qryItemNum, ItemNum) Then
              imgbtnPrev.Visible = (-1 < ItemNum)
            End If
          End If
        Catch err As Exception
          Response.Write(err.Message)
        End Try
    End If
End Sub

希望能帮助到你!

于 2013-03-01T20:21:05.180 回答