如何将列与gridview中的文本框进行比较

时间:2015-05-26 05:29:40

标签: asp.net gridview

我想问一下,我怎么能比较我的"数量与兑换"和"可用数量"当我在文本框中键入值时?

示例,在我的gridview中,我键入" 2"在文本框中,但仅可用数量" 1"。所以我希望显示错误显示数量不够。 我的验证只在gridview的最后一行完成

(我为我凌乱的编码技巧道歉,由于声誉低而无法发布图片,会在评论中截图)

点击我的按钮

Dim row As GridViewRow
    Dim strAvailable As String
    Dim strRedeem As String

    For Each row In GridView1.Rows
        ' write ur DB process code here
        strAvailable = CType(row.Cells(4).FindControl("lblAvailable"),Label).Text
        strRedeem = CType(row.Cells(5).FindControl("txtRedeem"), TextBox).Text

        If strRedeem > strAvailable Then
            lblMessage.Text = "Quantity not enough"
            btnPrint.Visible = False

        Else
            lblMessage.Text = "Enough Quantity"
            btnPrint.Visible = True
        End If
    Next
end sub

1 个答案:

答案 0 :(得分:0)

在为文本框分配值时,您需要调用ToString()方法,因为您正在连接string and int并将其分配给需要Text的文本框或标签的string属性。

lblMessage.Text = "Total number: " + totalA.ToString();

您正在比较two strings,但您需要比较两个int variables,因此您需要转换string to int

Dim row As GridViewRow
Dim strAvailable As Integer
Dim strRedeem As Integer

For Each row In GridView1.Rows
     //write ur DB process code here
    strAvailable = CType(CType(row.Cells(4).FindControl("lblAvailable"),Label).Text,int);
    strRedeem =CType(CType(row.Cells(5).FindControl("txtRedeem"), TextBox).Text,int);

    If strRedeem > strAvailable Then
        lblMessage.Text = "Quantity not enough"
        btnPrint.Visible = False

    Else
        lblMessage.Text = "Enough Quantity"
        btnPrint.Visible = True
    End If
Next

结束子

注意我不知道VB的确切语法,所以请原谅我,如果不正确,请予以纠正。

相关问题