0

質問UpdateColumns():メソッド(下記)またはイベント呼び出しのいずれかを変更して、OnTextChangedイベントを発生させている行のみを使用するにはどうすればよいですか?

現在、次のようにイベントをUpdateColumns()使用してメソッドを呼び出すことにより、GridViewセルの値を更新しています。OnTextChanged

<asp:TemplateField HeaderStyle-Width="35px">
    <ItemTemplate>
        <asp:TextBox OnTextChanged="UpdateColumns" ID="txtJan" CssClass="row"
        runat="server" AutoPostBack="True" Text='<%# Eval("Jan","{0:#0}") %>'>
        </asp:TextBox> 
    </ItemTemplate>
    <HeaderTemplate>
        Jan
    </HeaderTemplate>
    <FooterTemplate>
        <asp:TextBox ID="txtJan" CssClass="row" runat="server"></asp:TextBox>
    </FooterTemplate>
</asp:TemplateField>

以下は、イベントが発生するUpdateColumns()メソッドです。OnTextChangedテーブルの各行をループして計算を行います。GridViewには15列、10行あるため、操作が完了するまでに1秒ほどかかります。呼び出し元の行のみを表示するようにメソッドを変更するにはどうすればよいですか?基本的に、私は操作をより高速に実行し、無駄な計算を行わないようにしたいだけです。

Protected Sub UpdateColumns(ByVal sender As Object, ByVal e As EventArgs)
    Dim errors As New StringBuilder

    Try
        For Each row As GridViewRow In gvBuildingBlocks.Rows

            _tjan = CType(row.FindControl("txtJan"), TextBox)
            _tfeb = CType(row.FindControl("txtFeb"), TextBox)
            _tmar = CType(row.FindControl("txtMar"), TextBox)
            _tapr = CType(row.FindControl("txtApr"), TextBox)
            _tmay = CType(row.FindControl("txtMay"), TextBox)
            _tjun = CType(row.FindControl("txtJun"), TextBox)
            _tjul = CType(row.FindControl("txtJul"), TextBox)
            _taug = CType(row.FindControl("txtAug"), TextBox)
            _tsep = CType(row.FindControl("txtSep"), TextBox)
            _toct = CType(row.FindControl("txtOct"), TextBox)
            _tnov = CType(row.FindControl("txtNov"), TextBox)
            _tdec = CType(row.FindControl("txtDec"), TextBox)
            _tq1 = CType(row.FindControl("txtQ1"), TextBox)
            _tq2 = CType(row.FindControl("txtQ2"), TextBox)
            _tq3 = CType(row.FindControl("txtQ3"), TextBox)
            _tq4 = CType(row.FindControl("txtQ4"), TextBox)
            _th1 = CType(row.FindControl("txtH1"), TextBox)
            _th2 = CType(row.FindControl("txtH2"), TextBox)
            _tt = CType(row.FindControl("txtYear"), TextBox)

            If IsNumeric(_tjan.Text) And IsNumeric(_tfeb.Text) _
            And IsNumeric(_tmar.Text) And IsNumeric(_tapr.Text) _
            And IsNumeric(_tmay.Text) And IsNumeric(_tjun.Text) _
            And IsNumeric(_tjul.Text) And IsNumeric(_taug.Text) _
            And IsNumeric(_tsep.Text) And IsNumeric(_toct.Text) _
            And IsNumeric(_tnov.Text) And IsNumeric(_tdec.Text) Then
                _bbjan = Decimal.Parse(_tjan.Text)
                _bbfeb = Decimal.Parse(_tfeb.Text)
                _bbmar = Decimal.Parse(_tmar.Text)
                _bbapr = Decimal.Parse(_tapr.Text)
                _bbmay = Decimal.Parse(_tmay.Text)
                _bbjun = Decimal.Parse(_tjun.Text)
                _bbjul = Decimal.Parse(_tjul.Text)
                _bbaug = Decimal.Parse(_taug.Text)
                _bbsep = Decimal.Parse(_tsep.Text)
                _bboct = Decimal.Parse(_toct.Text)
                _bbnov = Decimal.Parse(_tnov.Text)
                _bbdec = Decimal.Parse(_tdec.Text)
                _bbq1 = _bbjan + _bbfeb + _bbmar
                _bbq2 = _bbapr + _bbmay + _bbjun
                _bbq3 = _bbjul + _bbaug + _bbsep
                _bbq4 = _bboct + _bbnov + _bbdec
                _bbh1 = _bbq1 + _bbq2
                _bbh2 = _bbq3 + _bbq4
                _bbtt = _bbh1 + _bbh2

                _tq1.Text = _bbq1.ToString()
                _tq2.Text = _bbq2.ToString()
                _tq3.Text = _bbq3.ToString()
                _tq4.Text = _bbq4.ToString()
                _th1.Text = _bbh1.ToString()
                _th2.Text = _bbh2.ToString()
                _tt.Text = _bbtt.ToString()

                _totalJan += _bbjan
                _totalFeb += _bbfeb
                _totalMar += _bbmar
                _totalApr += _bbapr
                _totalMay += _bbmay
                _totalJun += _bbjun
                _totalJul += _bbjul
                _totalAug += _bbaug
                _totalSep += _bbsep
                _totalOct += _bboct
                _totalNov += _bbnov
                _totalDec += _bbdec
                _totalQ1 += _bbq1
                _totalQ2 += _bbq2
                _totalQ3 += _bbq3
                _totalQ4 += _bbq4
                _totalH1 += _bbh1
                _totalH2 += _bbh2
                _totalT += _bbtt
            Else
                errors.Append("Error!  Input string must be numeric.  Please correct error(s).")
            End If
        Next

        If errors.Length > 0 Then
            'gvBuildingBlocks.DataSource = CType(Session("buildingBlocks"), DataTable)
            'gvBuildingBlocks.DataBind()
            ShowMessage(errors.ToString)
        End If

        _tjan = CType(gvBuildingBlocks.FooterRow.FindControl("txtJan"), TextBox)
        _tfeb = CType(gvBuildingBlocks.FooterRow.FindControl("txtFeb"), TextBox)
        _tmar = CType(gvBuildingBlocks.FooterRow.FindControl("txtMar"), TextBox)
        _tapr = CType(gvBuildingBlocks.FooterRow.FindControl("txtApr"), TextBox)
        _tmay = CType(gvBuildingBlocks.FooterRow.FindControl("txtMay"), TextBox)
        _tjun = CType(gvBuildingBlocks.FooterRow.FindControl("txtJun"), TextBox)
        _tjul = CType(gvBuildingBlocks.FooterRow.FindControl("txtJul"), TextBox)
        _taug = CType(gvBuildingBlocks.FooterRow.FindControl("txtAug"), TextBox)
        _tsep = CType(gvBuildingBlocks.FooterRow.FindControl("txtSep"), TextBox)
        _toct = CType(gvBuildingBlocks.FooterRow.FindControl("txtOct"), TextBox)
        _tnov = CType(gvBuildingBlocks.FooterRow.FindControl("txtNov"), TextBox)
        _tdec = CType(gvBuildingBlocks.FooterRow.FindControl("txtDec"), TextBox)
        _tq1 = CType(gvBuildingBlocks.FooterRow.FindControl("txtQ1"), TextBox)
        _tq2 = CType(gvBuildingBlocks.FooterRow.FindControl("txtQ2"), TextBox)
        _tq3 = CType(gvBuildingBlocks.FooterRow.FindControl("txtQ3"), TextBox)
        _tq4 = CType(gvBuildingBlocks.FooterRow.FindControl("txtQ4"), TextBox)
        _th1 = CType(gvBuildingBlocks.FooterRow.FindControl("txtH1"), TextBox)
        _th2 = CType(gvBuildingBlocks.FooterRow.FindControl("txtH2"), TextBox)
        _tt = CType(gvBuildingBlocks.FooterRow.FindControl("txtYear"), TextBox)

        _tjan.Text = _totalJan.ToString()
        _tfeb.Text = _totalFeb.ToString()
        _tmar.Text = _totalMar.ToString()
        _tapr.Text = _totalApr.ToString()
        _tmay.Text = _totalMay.ToString()
        _tjun.Text = _totalJun.ToString()
        _tjul.Text = _totalJul.ToString()
        _taug.Text = _totalAug.ToString()
        _tsep.Text = _totalSep.ToString()
        _toct.Text = _totalOct.ToString()
        _tnov.Text = _totalNov.ToString()
        _tdec.Text = _totalDec.ToString()
        _tq1.Text = _totalQ1.ToString()
        _tq2.Text = _totalQ2.ToString()
        _tq3.Text = _totalQ3.ToString()
        _tq4.Text = _totalQ4.ToString()
        _th1.Text = _totalH1.ToString()
        _th2.Text = _totalH2.ToString()
        _tt.Text = _totalT.ToString()

    Catch ex As Exception
        ShowError("Exception: ", ex.ToString())
    End Try
End Sub
4

1 に答える 1

2

「sender」引数には、イベントを発生させたコントロールを含める必要があります。送信者に基づいて何が変更されたかを把握し、変更された部分の計算のみをやり直すことができるはずです。

于 2013-02-18T20:41:29.220 に答える