所以我的文本框位于gridview的模板字段中。我想在页面加载时使用6个固定文本框。我认为那部分了。如果所有6个文本框都已填充,我想在选择下拉列值时添加新行。然后,下拉值将填充新行。我该怎么做?我知道基本的设置,但我只需要一些代码来检查是否所有文本框都已填满。
For Each row As GridViewRow In gvReq.Rows
Dim Index As Integer = row.RowIndex
Dim ReqText As TextBox = CType(gvReq.Rows(Index).FindControl("txtReqText"), TextBox)
Dim chkReq As CheckBox = CType(gvReq.Rows(Index).FindControl("chkReq"), CheckBox)
If ReqText.Text = "" Then
ReqText.Text = reader("RequireExceptText").ToString
chkReq.Checked = True
If Regex.IsMatch(ReqText.Text, "_") Then
Dim message As String = "The selected Requirement contains some blanks to fill."
Dim sb As New System.Text.StringBuilder()
sb.Append("<script type = 'text/javascript'>")
sb.Append("window.onload=function(){")
sb.Append("alert('")
sb.Append(message)
sb.Append("')};")
sb.Append("</script>")
ClientScript.RegisterClientScriptBlock(Me.GetType(), "alert", sb.ToString())
ReqText.Focus()
End If
Exit For
Else
Dim dtCurrentTable As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)
For Each row2 As GridViewRow In gvReq.Rows
If dtCurrentTable.Rows.Count >= 6 Then
If ReqText.Text <> "" Then
AddNewRow()
End If
End If
Exit For
Next
End If
Next
答案 0 :(得分:0)
我找到了解决问题的方法。效果很好!
Dim LastReqText As TextBox = DirectCast(gvReq.Rows(gvReq.Rows.Count - 1).FindControl("txtReqText"), TextBox)
If LastReqText.Text <> "" Then
AddNewRow()
End If
For i As Integer = 0 To gvReq.Rows.Count - 1
Dim ReqText As TextBox = DirectCast(gvReq.Rows(i).FindControl("txtReqText"), TextBox)
Dim chkReq As CheckBox = CType(gvReq.Rows(i).FindControl("chkReq"), CheckBox)
If ReqText.Text = "" Then
ReqText.Text = reader("RequireExceptText").ToString
chkReq.Checked = True
If Regex.IsMatch(ReqText.Text, "_") Then
Dim message As String = "The selected Requirement contains some blanks to fill."
Dim sb As New System.Text.StringBuilder()
sb.Append("<script type = 'text/javascript'>")
sb.Append("window.onload=function(){")
sb.Append("alert('")
sb.Append(message)
sb.Append("')};")
sb.Append("</script>")
ClientScript.RegisterClientScriptBlock(Me.GetType(), "alert", sb.ToString())
ReqText.Focus()
End If
Exit For
End If
Next