0

当点击gridview中的“更新”按钮时,有什么方法可以进行文字更新?文字由gridview的一列中所有值的总和填充,当gridview更新时,我还希望文字立即更新。gridView 是从 sql server 填充的。我的文字背后的代码是:

   protected void litBalance_Init(object sender, EventArgs e)
    {

        string queryString =
            "SELECT SUM(AuthorizationAmount) AS Balance FROM dbo.CPSTransaction WHERE (ApplicationIDPrimary = '" + Request.QueryString["WSUID"] + "')";
        using (SqlConnection connection =
                   new SqlConnection(ConfigurationManager.ConnectionStrings["OrientationConnectionString"].ConnectionString))
        {
            SqlCommand command =
                new SqlCommand(queryString, connection);
            connection.Open();

            SqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                reader.Read();
                litBalance.Text = reader["Balance"].ToString();
            }

            // Call Close when done reading.
            reader.Close();
        }
    }

它的 .net 是:

<asp:Literal ID="litBalance" runat="server" oninit="litBalance_Init"></asp:Literal>

我尝试使用标签而不是文字,并为gridview的编辑按钮和标签提供相同的ValidationGroup,但这不起作用。

在此先感谢您的帮助。

4

2 回答 2

1

Have you tried putting your literal edit code inside the RowCommand event handler for the GridView?

http://msdn.microsoft.com/en-US/library/system.web.ui.webcontrols.gridview.rowcommand(v=vs.80).aspx

于 2013-05-31T15:43:53.257 回答
0

我最终将代码放在 gv_RowUpdated 方法中:

protected void gvPaymentDetails_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{

    string balanceQueryString =
        "SELECT SUM(AuthorizationAmount) AS Balance FROM dbo.CPSTransaction WHERE (ApplicationIDPrimary = '" + Request.QueryString["WSUID"] + "')";
    using (SqlConnection balanceConnection =
               new SqlConnection(ConfigurationManager.ConnectionStrings["OrientationConnectionString"].ConnectionString))
    {
        SqlCommand balanceCommand =
            new SqlCommand(balanceQueryString, balanceConnection);
        balanceConnection.Open();

        SqlDataReader balanceReader = balanceCommand.ExecuteReader();

        if (balanceReader.HasRows)
        {
            balanceReader.Read();
            litBalance.Text = balanceReader["Balance"].ToString();
        }

        // Call Close when done reading.
        balanceReader.Close();
    }

}
于 2013-05-31T15:47:15.573 回答