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)
^这里是突出显示的地方。
答案 0 :(得分: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
答案 1 :(得分: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
希望它有所帮助!