VB.NET按钮单击事件此页面无法显示

时间:2015-01-06 16:40:12

标签: asp.net vb.net internet-explorer visual-studio-2012

我的问题涉及一个aspx页面,它有一个带有boundfields的gridview和带有文本框的模板,下拉列表和一个复选框。单击“创建集合”按钮时,它将直接进入“此页面无法显示”。

我在click事件的开头设置了断点。按下按钮后,永远不会触发此断点。错误屏幕立即出现。

另外需要注意的是,填充Gridview的SelectCommand通常会返回1000到2400个项目。 OnRowDataBound函数填充模板字段中的下拉列表。

除了最后一步之外,一切都正常;在SQL表中创建集合并重定向到应用程序的主页。

enter image description here

VB.NET代码

Protected Sub btnCreate_Click(sender As Object, e As EventArgs) Handles btnCreate.Click
    Try
        For Each row As GridViewRow In grdCreate.Rows
            Dim chk As CheckBox = DirectCast(row.FindControl("chkSelect"), CheckBox)
            Dim qty As TextBox = DirectCast(row.FindControl("txtQty"), TextBox)
            Dim ref As DropDownList = DirectCast(row.FindControl("ddlRef"), DropDownList)
            Dim method As DropDownList = DirectCast(row.FindControl("ddlMethod"), DropDownList)
            Dim hours As TextBox = DirectCast(row.FindControl("txtHours"), TextBox)
            Dim equip As DropDownList = DirectCast(row.FindControl("ddlEquipment"), DropDownList)
            Dim saoi As TextBox = DirectCast(row.FindControl("txtSAOI"), TextBox)
            Dim notes As TextBox = DirectCast(row.FindControl("txtNotes"), TextBox)

            Dim count As Integer = 1
            If chk IsNot Nothing And chk.Checked Then
                strSql = "INSERT INTO [Collections] ([Collection], [Nomenclature], [PartNumber], [Reference], [Method], [Hours], [Equipment], [SAOI], [Notes]) " & _
                    "VALUES ('" & txtName.Text & "','" & row.Cells(1).Text & "','" & row.Cells(2).Text & "','" & _
                    ",'" & ref.SelectedItem.ToString & "','" & method.SelectedItem.ToString & "','" & hours.Text & "','" & equip.SelectedItem.ToString & "' " & _
                    ",'" & saoi.Text & "','" & notes.Text & "') "
                cmd = New SqlCommand(strSql, cnnNDI)
                cmd.CommandTimeout = 500
                cnnNDI.Open()
                If (qty.Text = "" Or qty.Text = "1") Then
                    cmd.ExecuteNonQuery()
                Else
                    While count <= Convert.ToInt32(qty.Text)
                        cmd.ExecuteNonQuery()
                        count = count + 1
                    End While
                End If
                cnnNDI.Close()
            End If
        Next
        Dim msg As String = "Collection Created"
        ScriptManager.RegisterClientScriptBlock(Page, GetType(Page), "class", "alert(""" & msg & """);", True)
        Response.Redirect("~/NDT/home.aspx")
    Catch ex As Exception
        ScriptManager.RegisterClientScriptBlock(Page, GetType(Page), "class", "alert(""" & ex.Message & """);", True)
    End Try
End Sub

ASPX代码

<asp:GridView ID="grdCreate" runat="server" AllowPaging="false" AlternatingRowStyle-BackColor="LightGray" DataSourceID="SQLCreate"
        align="center" AutoGenerateColumns="false" OnRowDataBound="grdCreate_RowDataBound">
        <Columns>
            <asp:TemplateField HeaderText="Select">
                <ItemTemplate>
                    <asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="false" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField HeaderText="Nomenclature" DataField="Nomenclature" />
            <asp:BoundField HeaderText="Part Number" DataField="PartNumber" />
            <asp:TemplateField HeaderText="QTY">
                <ItemTemplate>
                    <asp:TextBox ID="txtQty" runat="server" Width="25px" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Reference">
                <ItemTemplate>
                    <asp:DropDownList ID="ddlRef" runat="server" AppendDataBoundItems="true" Width="150px"
                        DataTextField="Reference" DataValueField="Reference">
                        <asp:ListItem>--SELECT--</asp:ListItem>
                    </asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Method">
                <ItemTemplate>
                    <asp:DropDownList ID="ddlMethod" runat="server" AppendDataBoundItems="true"
                        DataTextField="Method" DataValueField="Method">
                        <asp:ListItem>--SELECT--</asp:ListItem>
                        <asp:ListItem>ET</asp:ListItem>
                        <asp:ListItem>MT</asp:ListItem>
                        <asp:ListItem>PT</asp:ListItem>
                        <asp:ListItem>RT</asp:ListItem>
                        <asp:ListItem>UT</asp:ListItem>
                        <asp:ListItem>VT</asp:ListItem>
                    </asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Hours">
                <ItemTemplate>
                    <asp:TextBox ID="txtHours" runat="server" Width="25px" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Equipment">
                <ItemTemplate>
                    <asp:DropDownList ID="ddlEquipment" runat="server" AppendDataBoundItems="true" Width="150px"
                        DataTextField="Equipment" DataValueField="Equipment">
                        <asp:ListItem>--SELECT--</asp:ListItem>
                    </asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Area of Interest">
                <ItemTemplate>
                    <asp:TextBox ID="txtSAOI" runat="server" Width="150px" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Result Notes">
                <ItemTemplate>
                    <asp:TextBox ID="txtNotes" runat="server" Width="150px" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

1 个答案:

答案 0 :(得分:0)

在网格(数据)绑定中使用Command.CommandTimeout = 8000(或更多)