如何比较gridview中的列和文本框
How to compare the column with textbox in gridview
请问,在文本框中输入值时,如何比较"Quantity to Redeem"和"Quantity Available"?
例如,在我的gridview中,我在文本框中输入“2”,但可用数量只有“1”。所以我想显示错误,显示数量不够。
我的验证只会在 gridview 的最后一行完成
(我为我乱码的技能道歉,由于声誉低,我无法post图像,将在评论中截图)
我的按钮点击
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
您需要在为文本框赋值时调用 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的确切语法所以请原谅我,如果不正确请更正。
请问,在文本框中输入值时,如何比较"Quantity to Redeem"和"Quantity Available"?
例如,在我的gridview中,我在文本框中输入“2”,但可用数量只有“1”。所以我想显示错误,显示数量不够。 我的验证只会在 gridview 的最后一行完成
(我为我乱码的技能道歉,由于声誉低,我无法post图像,将在评论中截图)
我的按钮点击
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
您需要在为文本框赋值时调用 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的确切语法所以请原谅我,如果不正确请更正。